Gradually converting an application from classic .asp to .aspx and just got stuck on checking the database connection. The first bit of code works fine in my .asp application;
<%' use this meta tag instead of adovbs.inc %>
<!--METADATA TYPE="typelib" uuid="00000205-0000-0010-8000-00AA006D2EA4" -->
' SQL database connection and result sets
Dim hSQLOne, RSQueryOne, SQLQuery
On Error Resume Next
Set hSQLOne = Server.CreateObject("ADODB.Connection")
hSQLOne.Open EMSGSRC
If hSQLOne.State = adStateOpen then
nSQLconnected = 1
Processing...
but when I converted it to .aspx like this;
<%' use this meta tag instead of adovbs.inc %>
<!--METADATA TYPE="typelib" uuid="00000205-0000-0010-8000-00AA006D2EA4" -->
' SQL database connection and result sets
Dim hSQLOne As ADODB.Connection
Dim RSQueryOne As ADODB.Recordset
Dim SQLQuery As String
On Error Resume Next
hSQLOne = New ADODB.Connection
hSQLOne.Open (EMSGSRC)
If hSQLOne.State = adStateOpen Then
nSQLconnected = 1
Processing...
I get this error;
Compiler Error Message: BC30451: Name 'adStateOpen' is not declared.
Ok, fair enough, tried removing the METADATA tag and just declaring the connection state constants within the application like this;
'---- ObjectStateEnum Values ----
Const adStateClosed As Short = &H0s
Const adStateOpen As Short = &H1s
Const adStateConnecting As Short = &H2s
Const adStateExecuting As Short = &H4s
Const adStateFetching As Short = &H8s
but "If hSQLOne.State = adStateOpen Then" doesn't match so it doesn't do anything.
Must have declared something wrong here or not checking the State properly.
Any help appreciated....
The very next day this post by @Raybarg Check if ADODB connection is open solved it!
If (hSQLOne.State And adStateOpen) = adStateOpen Then
nSQLconnected = 1
And do the stuff I want to do...