I put together a function (in VBScript in an ASP Classic website) to open a new MS SQL ADO connection, and found that if error handling is enabled, an error code of 424, with a description of "Object Required" occurs. I looked up this error, and everything that I find on it, is relative to Microsoft Excel. A valid and working connection object is still created, but you cannot make decisions in code (using the error response), to ascertain whether or not a proper connection object was created.
My question is, is this the expected behavior, and if yes, how would I go about making sure that the connection object has been instantiated correctly? Please note that when I tried to contact Microsoft about this behavior, the following statement appeared on the page:
Post VBA programming questions to Stack Overflow by using the vba tag, along with any other relevant tags.
The code snippet from the function is included as follows:
On Error Resume Next
' Instantiate the new DB Connection object:
Set objTemporary = Server.CreateObject("ADODB.Connection")
objTemporary.ConnectionTimeout = cServerConnectionTimeout
objTemporary.CommandTimeout = cServerCommandTimeout
objTemporary.ConnectionString = sSQLConnectionString
objTemporary.Mode = adModeReadWrite
objTemporary.Open
If Debug_OpenDBConnection = True Then
Response.Write("<br>LINE-336 (dataaccess.asp): This is the value of the objTemporary object: ") & objTemporary & "<br>"
Response.End
End If
' Check to see if an error occurred:
If Err.Number <> 0 Then
If Debug_OpenDBConnection = True Then
Response.Write("<br>LINE-345 (dataaccess.asp): This is the value of Err.Number: ") & Err.Number & "<br>"
Response.Write("This is the value of Err.Source: ") & Err.Source & "<br>"
Response.Write("This is the value of Err.Description: ") & Err.Description & "<br>"
Response.End
Else
Redim aOpen_DB_Connection(4)
aOpen_DB_Connection(0) = False
aOpen_DB_Connection(1) = 2
aOpen_DB_Connection(2) = Err.Number
aOpen_DB_Connection(3) = Err.Source
aOpen_DB_Connection(4) = Err.Description
OpenDBConnection = aOpen_DB_Connection
Exit Function
Response.End
End If
Else ' No error occured, so exit function, returning the new connection object:
Redim aOpen_DB_Connection(1)
aOpen_DB_Connection(0) = True
aOpen_DB_Connection(1) = objTemporary
OpenDBConnection = aOpen_DB_Connection
Exit Function
Response.End
End If
More of the function's code can be included if necessary, including the contents of the sSQLConnectionString
variable. Of interest is the fact that the error reporting object will work fine (report the correct type of error) if indeed a second OPEN command is subsequently issued anytime after the first object has been opened and before it has been closed. This seems to be because the object is available for the error reporting mechanisms to function.