On Error Resume Next
Set con = Server.CreateObject( "ADODB.Connection" )
con.Open "Provider=myOracleProvider;Data Source=myOracleDB;User Id=myUsername;Password=myPassword;"
If Err.Number = 0 And con.Errors.Count = 0 Then
'No problems connecting to DB so don't do anything
ELSE
'Problems connecting to DB so do something to handle this or alert adm
END IF
On Error goto 0
dim error_string 'initiate the variable
function readAndSetErrors(msg) 'Custom error message function
if err <> 0 then
error_string = error_string & " " msg 'Add the custom error message if there is an error
end if
set err = 0 'rest the error
end function
On Error Resume Next
'Connection string
strConnection = "driver={oracle in instantclient_11_2};DataSource=XYZ;Uid=username;Pwd=password;"
Set objConn = Server.CreateObject("ADODB.Connection") ' create connection object
set err = 0 'Reset the err just in case
objConn.Open (strConnection ) ' open the connection
function readAndSetErrors("The database is currently unavailable at this time") 'execute the function
' more code and may be more function calls
Response.write(error_string)
2 回答
这是我用的;
显然,调整连接字符串以适合您的特定Oracle环境和数据库凭据 .
在经典的asp中有类似try语法的尝试 . 接下来使用错误恢复 . 请在Try-Catch-End Try in VBScript阅读更多内容 . 然后,您可以在数据库连接初始化之前将错误状态重置为0 . 您甚至可以使用函数来收集所有错误消息,并在最后显示 .