Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Connecting and disconnection

Author  Topic 

SQLError
Yak Posting Veteran

63 Posts

Posted - 2004-05-09 : 12:45:26
My program connects to a db using the following code:

Dim connStr As String
Dim query As String
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset


etc

-----
When I need to read or write to the database, I use this block of code to connect. Then I close the connection. Therefore, it is used many times in the program.

Should this be the practice or should I only open one connection when the program is opened, and then close it when the program is exited?
I.e should "conn" be a global variable?

thanks.


Merkin
Funky Drop Bear Fearing SQL Dude!

4970 Posts

Posted - 2004-05-09 : 19:40:03
Open and close connections as quickly as possible. ADO pools connections, so they actually stay open in the background so it's very quick. Pooling works best when you return a connection to the pool as quickly as you can.

So you are on the right track, every time you need to use a connection, open it, grab your recordset and close it as quickly as possible.


Damian
Go to Top of Page
   

- Advertisement -