How to deal the error handling in VB program when there appear SQL_ERROR or SQL_SUCCESS_WITH_INFO?
It uses adodb.sqlerror object instead of err object to get the native errors from the DBMaker for that err object can’t get the native error codes of the database.
Following is the sample to do the error handling in VB program
// VB
Dim objConn As New ADODB.Connection
On Error GoTo ErrorHandle
objConn.Open "dsn=dbsample4"
objConn.Execute "insert into t1 values (2, '12345678901234567abcdefg')"
If objConn.Errors.Item(0).NativeError = 63 Then 'success with info
Err.Raise objConn.Errors.Item(0).NativeError, objConn.Errors.Item(0).Source, objConn.Errors.Item(0).Description, objConn.Errors.Item(0).HelpFile, objConn.Errors.Item(0).HelpContext
End If
Set objConn = Nothing
ErrorHandle:
Err.Raise objConn.Errors.Item(0).NativeError, objConn.Errors.Item(0).Source, objConn.Errors.Item(0).Description, objConn.Errors.Item(0).HelpFile, objConn.Errors.Item(0).HelpContext
Set objConn = Nothing