I've noticed that when a query is run in VBA, VBA doesn't always inform errors raised by it. For example if I try to do a bulk insert with a null value in a row that doesn't accept nulls I get this error in SQL Server:
Msg 4869, Level 16, State 1, Line 1
The bulk load failed. Unexpected NULL value in data file row 2, column 7. The destination column (IFSFxRate) is defined as NOT NULL.
However it doesn't raise any errors when I execute it with ADODB, though I noticed that if I do rs.NextRecordset I get an debug window with the error message.
Public Sub ExecuteQuery(sql As String) Dim Error As ADODB.Error
Dim Error As ADODB.Error
Dim rs As ADODB.recordset
Dim Conn As New ADODB.Connection
Conn.CommandTimeout = 0
Call Conn.Open(ConfigFactory.DB_CONNECTION)
Set rs = Conn.Execute(sql) ' "raiserror ('xyz', 10, 127)"
Debug.Print Conn.Errors.Count ' Returns 0
rs.NextRecordset ' The bulk load failed. Unexpected NULL value in data file row 2
Connection.Close
Set Connection = Nothing
End Sub
Why is the error not raised on .Execute? Is there something I can do to get the log in these cases?
On Error Resume Next?