VB.net + Retriving MS SQL Messages

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi There,

I have written an SQL script which i run though a VB.net application. It has
some print statements in which print results of the Script to the message
window if you run the script in the Query Analyser. Is there a way or getting
these messages in vb.net. Ive had a look round but no one seems to have done
it before. I suppose i could just write the results to another table, but i
like the idea of trying to capture the messages.

Hope someone can help me out.

Reagrds

James
 
Hi,

Maybe this will help.
http://msdn.microsoft.com/library/d...settingupsqldebuggingenablingsqldebugging.asp

Ken
-------------------------
Hi There,

I have written an SQL script which i run though a VB.net application. It has
some print statements in which print results of the Script to the message
window if you run the script in the Query Analyser. Is there a way or
getting
these messages in vb.net. Ive had a look round but no one seems to have done
it before. I suppose i could just write the results to another table, but i
like the idea of trying to capture the messages.

Hope someone can help me out.

Reagrds

James
 
Handle the the InfoMessage event in the SqlConnection object and have at
look at e.Errors.

Public WithEvents cn As SqlConnection

Private Sub cn_InfoMessage( _
ByVal sender As Object, _
ByVal e As System.Data.SqlClient.SqlInfoMessageEventArgs _
) Handles cn.InfoMessage
For Each err As System.Data.SqlClient.SqlError In e.Errors
If err.State = 1 Then
'not an error, an info message
Else
'State <> 1 means it really is an error
End If
Next
End Sub

This will capture any PRINT statements you put in stored procedures or
triggers, which can be very, very useful for debugging. I put descriptive
PRINT statements in most of my triggers.

HTH,
Bob
 
Back
Top