ASP经典如何连接到Oracle链接服务器时捕获错误 [英] asp classic how to trap errors when connecting to an oracle linked server
问题描述
我有这样的传统的ASP查询:
I have a query in classic ASP like this:
sql_test="select * from Openquery(it_test, 'select * from IT_DB.HOST')
问题是,我想测试执行,并得到一个错误页面上之前链接服务器的连接。
the problem is that I want to test the connection to the linked server before executing it and getting an error on the page.
如果链接服务器的连接不能正常工作。(例如:DB下)我可以在本地SQL服务器2000分贝避免在页面上得到一个错误在执行查询
If the connection to the linked server doesn't work (ex: db down) I can execute a query on the local SQL server 2000 db avoiding getting an error on the page.
推荐答案
我倾向于使用这个code ...
I tend to use this code...
'GetDataSet error columns...
const C_ERROR = "ERROR" 'Used when an error is generated - to be fed to the comsuming routine
const C_NO_DATA = "NO_DATA" 'Used when no data is returned to a consuming routine
const C_COL_IDENTIFIER = 0
const C_COL_ERROR_ID = 1
const C_COL_ERROR_MESSAGE = 2
const C_COL_SQL = 3
const C_COL_CONNECTION = 4
'GetDataSet
' Returns a table of data based on the supplied SQL statement and connection string.
'Parameters:
' sqlString (string) - The SQL string to be sent.
' connString (string) - The database connection string.
'Usage:
' dataSet = GetDataSet(sqlString, connString)
'Description:
' This function generates a table of information in a 2 dimensional array. The first dimension represents the columns
' and the second the rows. If an error occurs while the routine is executing the array and the base index (0,0) is set
' to C_ERROR, (0,1) to the VBScript error index, and (0,2) to the VBScript error description.
function GetDataSet(sqlString, connString)
'Initialise...
dim returnVal, rsData
on error resume next
'Define and open the recordset object...
set rsData = Server.CreateObject("ADODB.RecordSet")
rsData.Open sqlString, connString, 0, 1, 1
'Initialise an empty value for the containing array...
redim returnVal(0,0)
returnVal(0,0) = C_NO_DATA
'Deal with any errors...
if not rsData.EOF and not rsData.BOF then
'Store the data...
returnVal = rsData.GetRows()
select case err.number
case 3021 'No data returned
'Do nothing as the initial value will still exist (C_NO_DATA)
case 0 'No error
'Do nothing as data has been returned
case else
redim returnVal(4,0)
returnVal(C_COL_IDENTIFIER,0) = C_ERROR
returnVal(C_COL_ERROR_ID,0) = err.number
returnVal(C_COL_ERROR_MESSAGE,0) = err.description
returnVal(C_COL_SQL,0) = sqlString
returnVal(C_COL_CONNECTION,0) = connString
end select
end if
'Tidy up...
rsData.close
set rsData = nothing
on error goto 0
'Return the array...
GetDataSet = returnVal
end function
要得到我的数据集。它返回一个数组,你可以把手男人(ermm ...女人柄?)只要你喜欢。
To get my data sets. It returns an array that you can man handle (ermm ... woman-handle?) as you like.
如果有细节都在阵列的适当元件返回一个错误。
If there's an error the details are returned in the appropriate elements of the array.
这篇关于ASP经典如何连接到Oracle链接服务器时捕获错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!