【发布时间】:2010-04-21 13:45:21
【问题描述】:
我的数据库连接例程可能会失败,例如,如果提供了不正确的凭据。 在这种情况下,将抛出一般 OleDbException,ErrorCode 为 -2147217843。 该消息给出了一个错误,例如
No error message available, result code:
DB_SEC_E_AUTH_FAILED(0x80040E4D)
我如何捕捉到这个?使用错误代码 -2147217843 似乎有点“神奇的数字”。
Try
mCon = New OleDbConnection(connectionString)
mCon.Open()
Catch ex As OleDbException
If ex.ErrorCode = -2147217843 Then
Engine.logger.Fatal("Invalid username and/or password", ex)
Throw
End If
Catch ex As Exception
Engine.logger.Fatal("Could not connect to the database", ex)
Throw
End Try
【问题讨论】:
标签: .net error-handling