tags:

views:

62

answers:

2

I have been trying to adapt my code (a webservice) to get the SQLServerMessages:

SqlConnection c = new SqlConnection(ConfigurationManager.ConnectionStrings["db"].ConnectionString);

//capture the infomessage event to capture
c.InfoMessage += delegate(object sender, SqlInfoMessageEventArgs e)
{
    serverMessages += e.Message; //"\n" + e.Message
};

SqlDataAdapter dAdapter = new SqlDataAdapter(query, c);
SqlCommandBuilder cBuilder = new SqlCommandBuilder(dAdapter);

DataTable dTable = new DataTable("C");
dAdapter.Fill(dTable);

But while the dTable fills up nicely, the serverMessages-String remains empty (which should return at least 1 line. just like MS SQL Server MMS.) I am obviously missing something important. Any help is appreciated!

A: 

The InfoMessage event only broadcasts PRINT statements and low-level errors (severity 10 or lower), not the row count message.

To test your code (which looks fine), try adding a PRINT statement to your command's text or to the underlying procedure.

If you want to capture row counts, just add something like this after the appropriate statement(s):

PRINT   '(' + cast(@@Rowcount as varchar(32)) + ' row(s) affected)'
Jeff Sternal
A: 

InfoMessage only captures output of PRINT statements.

Probably some lines of your TSQL code would help us.

devio