Check for valid SQL server connection
"Robert W. King" wrote ...
I want to do beforehand is to check whether I have a valid connection
established to the SQL server database. I presume that there is some
property, et cetera I can test immediately following the cn.Open statement
that should let me find out whether the open was successful
As you are opening the Connection synchronously, you would get a
run-time error if the connection failed. If you are riding over
run-time errors (e.g. using On Error Resume Next) you could
subsequently check the connection's State property.
Alternatively, you could connect asynchronously but sinking the
Connection object's events in a class module and get any error message
when the ConnectComplete event e.g.
Option Explicit
Private WithEvents m_Con As ADODB.Connection
Private Sub m_Con_ConnectComplete( _
ByVal pError As ADODB.Error, _
adStatus As ADODB.EventStatusEnum, _
ByVal pConnection As ADODB.Connection)
End Sub
Jamie.
--
|