Oracle DB用户锁定VBScript

时间:2019-04-01 06:48:05

标签: oracle vbscript

我有一个简单的VBScript来测试与Oracle数据库的连接:

Dim strSQL, strDataSource, strUsername, strPassword

Set dbData = CreateObject("ADODB.Recordset")
Set dbConnection = CreateObject("ADODB.Connection")

dbConnection.ConnectionString = "Provider=OraOLEDB.Oracle;Data Source="MyDB";User ID="MyUser";Password="MyPassword";"
dbConnection.Open

strSQL = "SELECT 1 FROM DUAL"
dbData.Open strSQL, dbConnection
If (dbData.EOF) Then
    WScript.Echo "There are No records to retrieve"
Else
    WScript.Echo "There are records to retrieve."
End If

dbData.Close
dbConnection.Close

该脚本正在查询DUAL表,以及是否检索到1行。这表明数据库处于联机状态。

问题是,有时与我一起使用的用户帐户被锁定在数据库上,并且我从脚本中得到以下错误输出:

  

ORA-28000:帐户已锁定

有什么办法可以在VBScript中捕获此错误?

因为如果用户被锁定,我想在脚本中添加另一个Echo

1 个答案:

答案 0 :(得分:0)

对我来说,这有效:

Set con = CreateObject("ADODB.Connection")
con.provider = "OraOLEDB.Oracle"

On Error Resume Next
con.Open "Data Source=" & MyDB, "MyUser", "MyPassword"
If Err.Number <> 0 Then 
    WScript.Echo "Error: " & Err.Description
    WScript.Quit
End If
Err.Clear
On Error GoTo 0

WScript.Echo "Connection successful"
con.Close

输出:

Error: ORA-28000: the account is locked

您可以过滤

之类的错误
If InStr(1, Err.Description, "ORA-28000:", vbTextCompare) > 0 Then 
    WScript.Echo "Ask your Admin to unlook your account."
End If