Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB & connection strings 2

Status
Not open for further replies.

Greyfleck

IS-IT--Management
Jun 2, 2008
61
GB
I am using VS 2008 with sql server 2008
I wish to write a small test app to try out my new found skills but have hit a brick wall.
I do not wish to use the binding adapters et al (so called VCR controls) but wish to utilise my ADO.net skills thru code.

My 'brick wall' is in the connection. Do I connect to the DB in startup (behind my flash screen) and then leave the connection open until the App closes OR do I connect to the DB on entry to each form and close on exit?

I am hoping this is a really easy question to answer as I am bamboozled by the amount of info out there.

I should point out that I have converted from Access 2007 and that is where my knowledge lies.

Many thanks for your help ...

Jon
 
I guess that'll depend on how much you intend to access the database.

I've got some programs that constantly send SQL statements and get recordsets via an ADO connection, so I start the connection as soon as the program starts and close it when the program ends.

Other programs will only need to use a particular database once, so those wait 'til the database is needed before opening the connection.
 
This probably belongs in a VB.Net forum.


Generally though the answer "depends."

If the database access is infrequent compared with the life of the program, open/use/close connections. If the nature of the program involves a lot of different updates fairly frequently use a connection open for the life of the program.

For example if the user interaction is patterned like a forum web site (retrieve, display, lots of think time, then an update is posted) using short connections can increase scalability.

However if lots of query/updating goes on in rapid succession the open/close overhead will limit scalability.
 
I think there is a general thought / rule:

Connections are expensive. Recordsets are cheap.

This is, of course, with respect to the execution time, so the above advice fits to this thought in a general way, but may provide a background for the details.



MichaelRed


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top