muntasirrahman
asked on
How to check whether database connection is dropped?With out having any dummy Query
I am using adodb as follows:
Public ConnectDatabase As New ADODB.Connection
Public Sub ConnectCurrent()
Dim ConnectionString As String
On Error GoTo errdesc
ConnectionString = "uid=sa;pwd=;dsn=NPIL"
ConnectDatabase.Open ConnectionString
ConnectDatabase.CursorLoca tion = adUseClient
Exit Sub
errdesc:
MsgBox Err.Description, vbInformation, "Information"
If ConnectDatabase.State = 1 Then ConnectDatabase.Close
End
End Sub
…….
While running my program NT/Database connection may break, so I would like to test whether database connection is dropped or not. If dropped then again connect it.
I have tried as follows
If ConnectDatabase.State =0 Then
ConnectDatabase.Close
Call ConnectCurrent
End If
But after successful connection it alwas shows 1,though it has been disconnected from database.
How to do that one, can any one help me…
Public ConnectDatabase As New ADODB.Connection
Public Sub ConnectCurrent()
Dim ConnectionString As String
On Error GoTo errdesc
ConnectionString = "uid=sa;pwd=;dsn=NPIL"
ConnectDatabase.Open ConnectionString
ConnectDatabase.CursorLoca
Exit Sub
errdesc:
MsgBox Err.Description, vbInformation, "Information"
If ConnectDatabase.State = 1 Then ConnectDatabase.Close
End
End Sub
…….
While running my program NT/Database connection may break, so I would like to test whether database connection is dropped or not. If dropped then again connect it.
I have tried as follows
If ConnectDatabase.State =0 Then
ConnectDatabase.Close
Call ConnectCurrent
End If
But after successful connection it alwas shows 1,though it has been disconnected from database.
How to do that one, can any one help me…
I use something like this to check for it:
Select Case True
Case cnConn Is Nothing
Set cnConn = New ADODB.Connection
GoTo OPEN_CONN
Case cnConn.State = adStateClosed
GoTo OPEN_CONN
End Select
Leon
Select Case True
Case cnConn Is Nothing
Set cnConn = New ADODB.Connection
GoTo OPEN_CONN
Case cnConn.State = adStateClosed
GoTo OPEN_CONN
End Select
Leon
ASKER
Hi leonstryker,
It Does not work
It Does not work
ASKER
Hi leonstryker,
It Does not work
It Does not work
What is the problem?
Leon
Leon
ASKER
though Nt is dropped/Db is disconnected
'cnConn is nothing ' is false
'cnConn is nothing ' is false
But what is its State?
Does cnConn.State = adStateClosed catch it?
Leon
Does cnConn.State = adStateClosed catch it?
Leon
ASKER
yes,
it holds 1 mean
cnConn.State =adStateOpen
it holds 1 mean
cnConn.State =adStateOpen
Coul,d you show the code please.
Leon
Leon
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
if err.number = 12345 then 'number of error code
do something
end if