VB.net + Retriving MS SQL Messages

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
 
K

Ken Tucker [MVP]

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
 
B

Bob

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top