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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

adodb.connection timeout problem

Status
Not open for further replies.

zakman

Programmer
Aug 15, 2001
49
0
0
US
Hello everyone,

Suppose you have a program that establishes a database connection
upon program startup and closed the connection when the user exits.

Joe User starts the application (which opens the db connection),
then goes to town for 3 hours... when he returns, the connection
has apparently timed out (gee, wonder why??)...

Is there a way to check to see if the connection has timed out?

I have used the .state property to see if a connection is open or
closed, but didn't know if I could use that same .state to determine
if the connection actually timed out or it was lost...

What type of activity has occured on the connection? User authentication
with the database, then it sits idle (until the user specifies data to
be accessed).

Any ideas?
 


Hi Zakman:

I follow a simple procedure to avoid the hassles that you mention. When the program starts, it establishes a connection to the database, but does not open it. When something needs to be done with the database, then the program opens the database, does it thing, and then closes the database again. When the program exits, it releases the connection to the database.

For example:

At program start:
Code:
    m_cnnMyDB.ConnectionString = ". . ."

During the program:
Code:
    On Error Goto MyErrorHandler
    strSQL = "SELECT * FROM . . . "
    m_cnnMyDB.Open
    Set rsData = m_cnnMyDB.Execute(strSQL)
    ' Process the data
    Set rsData = Nothing
    If m_cnnMyDB.State <> adStateClosed Then m_cnnMyDB.Close
    On Error Goto 0

On program unload:
Code:
    Set rsData = Nothing
    If m_cnnMyDB.State <> adStateClosed Then m_cnnMyDB.Close

Just a suggestion.

Cassie
 


Hi:

My previous comment left out the major point: keep the database open for as short a time as reasonable.

If I need the data for longer than a quick change, then I copy the data to other controls or variables. My programs do not hold onto recordsets or open database connections for longer than necessary. Doing this may provide a little more safety on the actual database. Also, the &quot;left hand right hand&quot; problem doesn't occur since one block of code releases its connection before another block of code tries to access the database.

Cassie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top