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

ADODB Connection - Reconnect

Status
Not open for further replies.

Crazyec

Programmer
Aug 28, 2001
80
HK
Hi Pros., I have a application that connect to a SQL Server for retrieve the new data in every 5 minutes. But sometimes the SQL Server is disconnected. If I want to make my application retry the connection while the connection is downed and make it resume when the connection is back again, what should I do? Many thanks.
 
if Conn.state <> adstateopen then
set conn = nothing
reopen connection
end if

hope it helps
 
What if

Conn.State = 4 'adStateExecuting or
Conn.State = 8 'adStateFetching

if Conn.state <> adstateopen then
set conn = nothing
reopen connection
end if

might kill somebody!

better to check

If Conn.State = 0 Then 'adStateClosed
Set Conn = Nothing
reopen connection
End If
 
True true.

A better way still would be close the connection if it is doing nothing for 5 mins
 
In order to do this correctly you are going to have to perform a query against the database. If the connection is terminated the Conn.state is not updated and it will still be open.

I have posted an example here before. Try doing a keyword search to find it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top