You can catch these messages by like this:
Public Class Test
Private Shared Sub OnInfoMessage(ByVal sender As Object, _
ByVal args As SqlInfoMessageEventArgs)
Dim objError As SqlError
' Loop through all the error messages
For Each objError In args.Errors
' Display the error properties
MessageBox.Show("The " & objError.Source & _
" has raised a warning on the " & _
objError.Server & " server. These are the properties :" & _
vbCrLf & vbCrLf & "Severity: " & objError.Class & vbCrLf & _
"Number: " & objError.Number & vbCrLf & "State: " & _
objError.State & vbCrLf & "Line: " & objError.LineNumber &
vbCrLf & _
"Procedure: " & objError.Procedure & vbCrLf & "Message: " & _
objError.Message)
Next
' Display the message and the source
MessageBox.Show("Info Message: " & args.Message & _
vbCrLf & "Info Source: " + args.Source)
End Sub
Public Sub TriggerInfoMessageEvent()
Dim cmmUserMan As SqlCommand = _
New SqlCommand("RAISERROR('This is an info message event.', 10,
1)", _
prcnnUserMan)
' Open the connection
prcnnUserMan.Open()
' Execute the T-SQL command
cmmUserMan.ExecuteNonQuery()
End Class
Alternatively, you use the AddHandler statement to catch the like this:
AddHandler connection.InfoMessage, New SqlInfoMessageEventHandler(AddressOf
OnInfoMessage)
The problem with the RAISERROR statement is that the severity must be set to
19 or higher for it to trigger a "normal" exception.
--
Carsten Thomsen
Enterprise Development with VS .NET, UML, and MSF
http://www.apress.com/book/bookDisplay.html?bID=105
"Enzo Marinelli" <an*******@discussions.microsoft.com> wrote in message
news:7E**********************************@microsof t.com...
Hello everyone,
I have a HUGE database, with very complex stored procedures that handle
every possible error and the passed it to an ASP site with RAISERROR.
Now I need to use that same database on an ASP.NET site, but all I can do
is:
Try
Common.ExecuteNonQuery(QueryString, Common.Connection)
Catch Ex As SqlException
Result.Text = Ex.Message
Finally
Common.Connection.Close()
End Try
I really NEED to have the RAISERROR message... how can I do this?