0

我们有一个运行 IIS 6 和 ASP 经典的站点。我们连接到 Oracle 数据库以收集信息以显示在此网页上。当数据库关闭时,最终用户会看到关于无法连接到数据库的典型 asp 错误消息。我想显示一条自定义错误消息,其内容类似于“此时数据库当前不可用”。任何人都可以使用 oracle 连接字符串在 ASP 中提供语法来完成此操作吗?

谢谢。

4

2 回答 2

1

这就是我使用的;

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

显然调整连接字符串以适合您的特定 Oracle 环境和数据库凭据。

于 2013-11-06T11:12:57.600 回答
0

在经典的 asp 中有一个类似 try catch 的语法。接下来使用错误恢复。请在 VBScript 中的 Try-Catch-End Try 中阅读更多内容。然后您可以在数据库连接初始化之前将错误状态重置为 0。您甚至可以拥有收集所有错误消息并在最后显示的功能。

dim error_string 'initiate the variable

            function readAndSetErrors(msg) 'Custom error message function

                if err <> 0 then
                    error_string = error_string & "<br/>" 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)
于 2013-11-06T07:11:37.767 回答