?
Solved

retrieving  sql server error messsage from a trigger in VB6

Posted on 2003-03-06
4
Medium Priority
?
303 Views
Last Modified: 2006-11-17
I have a trigger that uses raiserror, ie
RAISERROR ('Error happened here.', 16, 1)

How can I obtain this error's string though VB code?

0
Comment
Question by:marshallgarza
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 2

Expert Comment

by:stiemark
ID: 8084046
On Error GoTo err_MyError

code
code
code


err_MyError:
    MsgBox prompt:="Error number: " & Err.Number & "- " & Err.Description, _
                   Buttons:=vbCritical + vbMsgBoxHelpButton, _
                   Title:="Edit Record Error", _
                   HelpFile:=Err.HelpFile, _
                   context:=Err.HelpContext
0
 

Author Comment

by:marshallgarza
ID: 8084169
I'm not getting the error message I specified in the trigger, ie ''Error happened here'
0
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 300 total points
ID: 8089771
Is this what you mean:

CREATE TABLE Table1 (
     ID int IDENTITY(1, 1) NOT NULL ,
     Now smalldatetime NULL)

__________________________________________

Create Trigger tr_Table_Inserted On dbo.Table1

After Insert

As

RAISERROR ('Error happened here.', 16, 1)

__________________________________________

CREATE Procedure usp_AddRow

As

Insert Table1 (Now) Values (GetDate())


Dim cn As ADODB.Connection
Dim cmd As ADODB.Command
Dim er As ADODB.Error

On Error GoTo ErrHandler

Set cn = New ADODB.Connection
With cn
    .ConnectionString = "Provider=SQLOLEDB.1;Password=yourpassword;Persist Security Info=True;User ID=yourusername;Initial Catalog=yourdatabase;Data Source=yourserver"
    .Open
    Set cmd = New ADODB.Command
    With cmd
        Set .ActiveConnection = cn
        .CommandText = "usp_AddRow"
        .CommandType = adCmdStoredProc
        .Execute , , adExecuteNoRecords
    End With
    Set cmd = Nothing
    .Close
End With
Set cn = Nothing

Exit Sub
ErrHandler:
If Not cn Is Nothing Then
    If cn.State = adStateOpen Then
        For Each er In cn.Errors
            Debug.Print er.Number, er.Description, er.NativeError, er.SQLState, er.Source
        Next
        cn.Close
    End If
    Set cn = Nothing
End If

If this does not work for you, let us know what version of SQL Server and Service Pack.

Anthony
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 8089810
If you are getting the error description: "Errors occurred", than check out this article from MSDN:
FIX: RAISERROR Does Not Work with SQLOLEDB Provider
http://support.microsoft.com/default.aspx?scid=kb%3Ben-us%3B217019

Anthony
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question