Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB6 :: Handling SQL Raiserror

Status
Not open for further replies.

RileyCat

Programmer
Apr 5, 2004
124
US
What's the trick to catching or handling a raiserror generated out of SQL? Even though I'm iterating through the ado Errors collection, the raiserror is actally coming out as a "Run Time Error". The part in my code where I actually look for errors is not being touched because the runtime error closes the app.

Here's my VB6 code calling my MS SQL SP, and my SQL Raierror . . .

Code:
    Dim adoCmd As New ADODB.Command
    Dim adoRs As New ADODB.Recordset
    Dim adoErr As ADODB.Error

    Set adoCmd = New ADODB.Command
   
    With adoCmd
        .ActiveConnection = gConnect
      
        .CommandType = adCmdStoredProc
        .CommandText = gcSQLSP_CAPPLUSSRCLOOKUP
      
        Call .Parameters.Refresh
        If (Hs > 0) Then
            .Parameters.Item("@Scn").Value = Scn
            .Parameters.Item("@IdTransaction").Value = Hs
            mServiceControlNumber = Scn
            mIdTransaction = Hs
        Else
            .Parameters.Item("@IdTransaction").Value = Scn
            mServiceControlNumber = ""
            mIdTransaction = Scn
        End If
        
        Set adoRs = .Execute

'THE RUNTIME ERROR POPS UP HERE EVEN BEFORE I GET TO THE 
'NEXT STATEMENT TO CHECK FOR ERRORS ........
        
        If (adoCmd.ActiveConnection.Errors.Count) Then
            Call MsgBox("ADO Connection Error!" + vbCrLf + vbCrLf + "Action : CapPlusSrc_Lookup", vbCritical + vbOKOnly, "Coupons Inc Logging")
            adoCmd.ActiveConnection.Errors.Clear
            CapPlusSrc_Lookup = False
            mCIOriginalTransaction = CIOriginalTransaction.adoErr
        End If

Code:
if	(@tmpIdTag <> dbo.fxBarcodeCheck(@IdTransaction))
begin
	raiserror ('Invalid Check Digit on NRS Store Tag Id', 14, 1)
	return (-1)
end

Any help would be most appreciated.

Thank in advance!

Stay Cool Ya'll! [smile2]

-- Kristin
 
Why not simply catch it in a regular old VB error handler?
Code:
Public Sub DoStuff()
On Error Goto MyErrHandler

<bunch of code>

Exit Sub

MyErrHandler:
  MsgBox "Um, yeah, so we got error # " & Err.Number & ": " & Err.Description & vbCrLf & "So what should we do, boss?"
End Sub

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top