Does adoCon.open in asp returns any value
I am establishing a connection to a mssql server database in asp using the co开发者_如何学JAVAmmand
adoCon.Open "Driver={SQL Server}; Server=" & host_name & "; Database=" & db_name & "; Uid=" & user_name & "; Pwd=" & password
Now my question is how to know if this connection establishment was successful. Does adoCon.open returns any value which I can use in my if statement?
I guess you are useing ADODB-ActiveX object... so that would be the property adoCon.State
.
- adStateClosed 0 -> The object is closed
- adStateOpen 1 -> The object is open
- adStateConnecting 2 -> The object is connecting
- adStateExecuting 4 -> The object is executing a command
- adStateFetching 8 -> The rows of the object are being retrieved
find more information here enter link description here
After this method successfully completes, the connection is live and you can issue commands against it and process the results.
So it returns when the connection is established; if for any reason it could not be created - invalid credentials, networking issue etc - it will raise an error which you should trap & deal with inline or in a helper routine.
function open(cn as adodb.connection) as boolean
on error goto handler
cn.Open "Driver={SQL Server}; Server=" & host_name & "; Database=" & db_name & "; Uid=" & user_name & "; Pwd=" & password
open=true
exit function
handler:
response.write "fail " & err.description
end function
精彩评论