diego75TO


HI!

i need to grab the "server message" from sql server when i execute a sql script.

i would retrive all messages , 'print' output too in order to put the messages into a textbox.

is this possible and how




Re: SERVER MESSAGES to textbox

Jens K. Suessmeyer


What server messages do you mean

Jens K. Suessmeyer

---
http://www.sqlserver2005.de
---







Re: SERVER MESSAGES to textbox

diego75TO

I mean i wolud capture all "output messages" including "the print output i include in mu sql script"

so,i run this query

print 'start'

select * from table1

i would retrieve all output including the 'start' string

...any suggest please






Re: SERVER MESSAGES to textbox

Jens K. Suessmeyer

A really simple one would be:

Code Block

static void Main(string[] args)

{

SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=master;INtegrated Security=True");

conn.FireInfoMessageEventOnUserErrors = true;

conn.InfoMessage += new SqlInfoMessageEventHandler(conn_InfoMessage);

conn.Open();

SqlCommand command = new SqlCommand("Print 'Started'", conn);

command.ExecuteNonQuery();

conn.Close();

}

static void conn_InfoMessage(object sender, SqlInfoMessageEventArgs e)

{

Console.WriteLine(e.Message);

}

In common there is this InfoMessage event where you can subscribe to after Setting the property FireInfoMessageEventOnUserErrors on the connection.

Jens K. Suessmeyer

---
http://www.sqlserver2005.de
---