SqlConnection.InfoMessage - SqlError.Class wrong value ?

S

Stephen Ahn

Hi,

Using VS2005, SQL Server 2005.

The SqlError.Class property always seems to be 0 when retrieving
informational messages via the SqlConnection.InfoMessage event. Sample code
to reproduce :

==
private void button1_Click(object sender, EventArgs e)
{
string yourConnString = // your connection string here


using (SqlConnection conn = new SqlConnection(yourConnString))
{
conn.Open();
conn.InfoMessage += new
SqlInfoMessageEventHandler(OnInfoMessage);
string sql = "raiserror('done', 10, 127)";
SqlCommand cmd = new SqlCommand(sql, conn);
cmd.ExecuteNonQuery();
}

}

protected void OnInfoMessage(
object sender, SqlInfoMessageEventArgs args)
{
foreach (SqlError err in args.Errors)
{
MessageBox.Show("Class " + err.Class + ", State " +
err.State);
}
}
==

The message box displays : "Class 0, State 127". I'm expecting to get 10
as the value of Class. Can anyone shed any ideas into this ?

TIA,
Stephen
 

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