Connection.Errors only contains ONE error

From: Tom Kelleher (kelleher_at_tkelleher.com)
Date: 06/01/04


Date: Tue, 01 Jun 2004 14:43:47 GMT

Okay, add me to the list of folks who are beating their brains
out trying to get Connection.Errors to return more than
the first error. No matter how many low-severity errors I put
into my SP or my SQL, no matter how many PRINT statements, no
matter whether I set the cursor client or server-side, no
matter whether I run my code in VB or VBScript...still
Connection.Errors.Count = 1

Here's the code I'm working with. I have stripped it down to
the bones. It uses both PRINT and RAISERROR, and I set the
severity of the latter to below 11 to avoid invoking the
VB Err object (yes, I'm aware of the MSDN articles about
the need to check the Err object). I can change the order
of the PRINT and RAISERROR commands to my heart's delight
but I still only get the first error. I've run my SQL raw
(as below) or in a stored procedure. I've tried calling
recordsets, or just firing PRINTs and RAISERRORs (as below).
When I do recordsets, I do them with server-side and client-
side cursors... I use SET NOCOUNT ON, or I don't use it,
it doesn't matter. I only ever get ONE error back.

(BTW, I'm using MSSQL 2000 SP2 and ADO 2.7)

'---------------------------------
Dim conn

'Get vanilla connection to SQL Server 2000
'using OLE-DB connection string
Set conn = Get_Connection("myDb")

Dim sql

'sql = "set nocount on " 'Has no effect either way

sql = sql & "print 'This is my first error' "
sql = sql & "RAISERROR ('This is my second error', 10, 2) "
sql = sql & "RAISERROR ('This is my third error', 10, 2) "

conn.execute sql

dim Errs, err, StrTmp, i
set Errs = conn.errors

strTmp = "Number of errors in conn.Errors collection: " & Errs.Count

For Each err In Errs
 i = i + 1
 With err
  StrTmp = StrTmp & vbCrLf & "Error #" & i & ":"
  StrTmp = StrTmp & vbCrLf & " ADO Error #" & .Number
  StrTmp = StrTmp & vbCrLf & " Native Error " & .NativeError
  StrTmp = StrTmp & vbCrLf & " Description " & .Description
  StrTmp = StrTmp & vbCrLf & " Source " & .Source
  StrTmp = StrTmp & vbCrLf & " SQLState " & .SQLState
 End With
Next

'Response.Write StrTmp 'For testing in the VBS/ASP world
MsgBox strTmp 'For testing in the VB world

'-------------------------------

My output from the above is...

  Number of errors in conn.Errors collection: 1
  Error #1:
     ADO Error #0
     Native Error 50000
     Description This is my first error
     Source Microsoft OLE DB Provider for SQL Server
     SQLState 01000

...The content of the error above is FINE, no problem. The
problem is that I only get one error. I would expect to see
three text blocks like the above. Why? How do I get
around this?

Thanks much in advance! Getting over this hump will be a big
help for me.

- Tom Kelleher



Relevant Pages

  • Connection.Errors only contains ONE error
    ... No matter how many low-severity errors I put ... VB Err object (yes, I'm aware of the MSDN articles about ... but I still only get the first error. ... I've run my SQL raw ...
    (microsoft.public.vb.database.ado)
  • Re: Connection.Errors only contains ONE error
    ... No matter how many low-severity errors I put ... > the need to check the Err object). ... I've run my SQL raw ... Microsoft OLE DB Provider for SQL Server ...
    (microsoft.public.data.ado)
  • Re: Connection.Errors only contains ONE error
    ... No matter how many low-severity errors I put ... > the need to check the Err object). ... I've run my SQL raw ... Microsoft OLE DB Provider for SQL Server ...
    (microsoft.public.vb.database.ado)
  • Re: Interesting article: In the Beginning: An RDBMS history
    ... For that matter, I don't know what the sql standard would mean by "table". ... Without those differences, I imagine an sql table still couldn't stand for any relation we choose because at least when I was using it ten or more years ago a row-column intersection contained only a single value, ie. some relations can't be expressed as one table. ... For example pi21(supply{project, supplier}) appear to be ...
    (comp.databases.theory)
  • Re: ODBC, PHP and a lack of understanding.
    ... > My problem consists of two parts, the first of which I imagine is only ... > the original SQL statement. ... a simplistic SQL parser to pull the information directly from the SQL ... Therefore I'd be grateful for any other advice on the matter. ...
    (comp.lang.php)