C
Chris Leonard
I am a C# newbie with experience in other languages who is writing a C# app
that talks to a SQL Server. I have the connection working, the queries are
working, error handling (try/catch/finally) is working, and life is (mostly)
good. However, I tried to use a delegate to display informational and
warning message (these are non-error messages not trapped by catch) and this
is *not* working. Here is what I believe to be the relevant part of my
code. I am calling a SQL Server stored procedure that I *know* raises a
message with severity level of 10 (informational), but doing a step-through
shows that my handler is not firing at all. What am I missing? The
following code is inside my form class (it's a thick-client app), if that
matters.
public delegate void OleDbInfoMessageEventHandler (Object sender,
OleDbInfoMessageEventArgs e);
public class DBMessageHandler
{
public static void MessageHandler (Object sender,
OleDbInfoMessageEventArgs e)
{
int i;
for (i = 0; i < e.Errors.Count; i++)
{
MessageBox.Show (e.Errors.ToString());
}
}
}
//DBMessageHandler dbmh = new DBMessageHandler();
OleDbInfoMessageEventHandler dbmh = new
OleDbInfoMessageEventHandler(DBMessageHandler.MessageHandler);
that talks to a SQL Server. I have the connection working, the queries are
working, error handling (try/catch/finally) is working, and life is (mostly)
good. However, I tried to use a delegate to display informational and
warning message (these are non-error messages not trapped by catch) and this
is *not* working. Here is what I believe to be the relevant part of my
code. I am calling a SQL Server stored procedure that I *know* raises a
message with severity level of 10 (informational), but doing a step-through
shows that my handler is not firing at all. What am I missing? The
following code is inside my form class (it's a thick-client app), if that
matters.
public delegate void OleDbInfoMessageEventHandler (Object sender,
OleDbInfoMessageEventArgs e);
public class DBMessageHandler
{
public static void MessageHandler (Object sender,
OleDbInfoMessageEventArgs e)
{
int i;
for (i = 0; i < e.Errors.Count; i++)
{
MessageBox.Show (e.Errors.ToString());
}
}
}
//DBMessageHandler dbmh = new DBMessageHandler();
OleDbInfoMessageEventHandler dbmh = new
OleDbInfoMessageEventHandler(DBMessageHandler.MessageHandler);