Error trapping with VB

Error trapping with VB

Post by ElecClrW » Thu, 15 Oct 1998 04:00:00



I am writing in VB5 and SQL Server 6.5 and am having trouble with RAISERROR.
When I call stored procedure B (hypothetical name) from stored procedure A, and
B does a RAISERROR and returns to A, then A does a RAISERROR and returns to the
VB code, the only error that gets back to VB is the one from B.

Is there some way get errors from multiple layers of stored procedures to
return to VB instead of returning only the first error encountered?

Thanks for any help you can give me.

Jeremy

 
 
 

Error trapping with VB

Post by Christer Romso » Fri, 16 Oct 1998 04:00:00


There are many ways of accessing SQL Server from VB. The exact details of
the answer depends on the way your using. (And most of them have their own
news group. The question isn't really appropriate for this one). If you're
using RDO, DAO or ADO then the library supports an error collection with an
error object for each error the query returned. Other apis have simmillar
things.

    Christer Romson

Jeremy:

Quote:>I am writing in VB5 and SQL Server 6.5 and am having trouble with
RAISERROR.
>When I call stored procedure B (hypothetical name) from stored procedure A,
and
>B does a RAISERROR and returns to A, then A does a RAISERROR and returns to
the
>VB code, the only error that gets back to VB is the one from B.

>Is there some way get errors from multiple layers of stored procedures to
>return to VB instead of returning only the first error encountered?


 
 
 

1. ADO error trapping in VB + SQL Server 2000

ADO 2.5
VB6
SQL Server 2000 SP2

Hi,

I have a function that inserts large amounts of rows (200,000+) into
an SQL Server 2000 db.

The function basically sends multiple buffers of 1000 "EXEC <my stored
procedure>" statements to an SQL Server using
ADODB.Connection.Execute.

This all works as I intended it to.  In the function I have an On
Error Goto that will handle ALMOST all errors that may occur.

The problem is that I need to allow for all errors, especially a
network failure in the middle of execution.  To simulate a network
failure, I start my function running, then after a minute or so I pull
the network lead out of my computer.  When the connection times out I
get " Run-time error '-2147418113 (8000ffff)' " and then my
application terminates.  This is the error I need to trap.  I am
assuming this error is generated by ADO and handled by VB (I could be
wrong though!).

I've tried putting an event handler on ADODB.Connection.InfoMessage
but it is never called.  The error occurs in an error handled section
of my code, but my standard error handling code is not called.

The code (cut down):

Dim WithEvents cn As ADODB.Connection

Function MyFunction()

  On Error Goto EH

  Dim i As Integer
  Set cn = New ADODB.Connection

  cn.ConnectionString = strMyConnectString
  cn.CommandTimeout = 0
  cn.Open

  For i = 0 to 100
   'Retrieve batch of 1000 EXEC stored procedure statements
    strSQLBatch = GetNextSQLBatch(i)

    cn.Execute(strSQLBatch)
  Next I

  cn.Close
  Set cn = Nothing

EH:
  LogError(Err.Description)
  Msgbox "An error has occurred: " & Err.Description

End Function

Private Sub cn_InfoMessage(ByVal pError As ADODB.Error, _
  adStatus As ADODB.EventStatusEnum, ByVal pConnection As
ADODB.Connection)

  MsgBox "SQL Warning: " & " " & pError.Description

End Sub

Any help is greatly appreciated!

Regards,
Dean

2. Kernel Parameters

3. HELP!!!!

4. DTS and error trapping in VB

5. Is MOE 4.0 Multithreaded?

6. Error Trapping: MS Access errors not trapped in VB code

7. Filemaker & Windows Pro 2000 - compatible???

8. Deadlock errors & vb error trapping

9. Error Trapping - Can you trap a DTS Package error using SQLDMO running a job

10. ado errors not trapped by vb error object???

11. Trapping SQL error in VB before ADO raises run-time error

12. How to Trap DB errors (VB) ??