HighTechTalks DotNet Forums  

SqlConnection.InfoMessage - SqlError.Class wrong value ?

Dotnet Framework (ADO.net) microsoft.public.dotnet.framework.adonet


Discuss SqlConnection.InfoMessage - SqlError.Class wrong value ? in the Dotnet Framework (ADO.net) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Stephen Ahn
 
Posts: n/a

Default SqlConnection.InfoMessage - SqlError.Class wrong value ? - 08-17-2007 , 01:07 AM






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



Reply With Quote
  #2  
Old   
Mary Chipman [MSFT]
 
Posts: n/a

Default Re: SqlConnection.InfoMessage - SqlError.Class wrong value ? - 08-23-2007 , 01:38 PM






Working with InfoMessages can be a bit tricky. The topic Working wtih
Connection Events should help:
http://msdn2.microsoft.com/en-us/lib...8w(VS.80).aspx

-mary

On Fri, 17 Aug 2007 15:07:38 +1000, "Stephen Ahn" <no_address> wrote:

Quote:
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


Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.