Connection.Errors only contains ONE error
From: Tom Kelleher (kelleher_at_tkelleher.com)
Date: 06/01/04
- Next message: Peter: "ADO - Connecting using a SQL Stored Procedure"
- Previous message: Randy: "Re: ADO Refresh Fails After Upgrading to Windows XP"
- Next in thread: Val Mazur: "Re: Connection.Errors only contains ONE error"
- Reply: Val Mazur: "Re: Connection.Errors only contains ONE error"
- Messages sorted by: [ date ] [ thread ]
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
- Next message: Peter: "ADO - Connecting using a SQL Stored Procedure"
- Previous message: Randy: "Re: ADO Refresh Fails After Upgrading to Windows XP"
- Next in thread: Val Mazur: "Re: Connection.Errors only contains ONE error"
- Reply: Val Mazur: "Re: Connection.Errors only contains ONE error"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|