Hi
I'm trying to get the InfoMessage code below working. What I'm
finding is that the print statements have to be before the select
statement, which kind of defies the point in my scenario.
e.g. here the event will fire for 'hi mum' but not for 'hi again'
What am I doing wrong here?
thanks
<add name="Northwind "
connectionStrin g="Integrated
Security=SSPI;d atabase=Northwi nd;server=local host;Connect Timeout=30;
Persist Security Info=False"
/>
private void ShowPrintStatem ents()
{
DbProviderFacto ry factory = SqlClientFactor y.Instance;
ConnectionStrin gSettings settings =
ConfigurationMa nager.Connectio nStrings["Northwind"];
string theConnectionSt ring = settings.Connec tionString;
DbConnection connection = factory.CreateC onnection();
if (connection is SqlConnection)
{
((SqlConnection )connection).In foMessage += new
SqlInfoMessageE ventHandler(Cha pter4_InfoMessa ge);
}
connection.Conn ectionString = theConnectionSt ring;
connection.Open ();
DbCommand command = factory.CreateC ommand();
command.Connect ion = connection; command.Command Type =
CommandType.Tex t;
command.Command Text = "print 'hi mum';select 1 as somecolumn;prin t
'hi again'";
DbDataReader reader = command.Execute Reader();
reader.Close();
}
void Chapter4_InfoMe ssage(object sender, SqlInfoMessageE ventArgs e)
{
string message = e.Message;
}
I'm trying to get the InfoMessage code below working. What I'm
finding is that the print statements have to be before the select
statement, which kind of defies the point in my scenario.
e.g. here the event will fire for 'hi mum' but not for 'hi again'
What am I doing wrong here?
thanks
<add name="Northwind "
connectionStrin g="Integrated
Security=SSPI;d atabase=Northwi nd;server=local host;Connect Timeout=30;
Persist Security Info=False"
/>
private void ShowPrintStatem ents()
{
DbProviderFacto ry factory = SqlClientFactor y.Instance;
ConnectionStrin gSettings settings =
ConfigurationMa nager.Connectio nStrings["Northwind"];
string theConnectionSt ring = settings.Connec tionString;
DbConnection connection = factory.CreateC onnection();
if (connection is SqlConnection)
{
((SqlConnection )connection).In foMessage += new
SqlInfoMessageE ventHandler(Cha pter4_InfoMessa ge);
}
connection.Conn ectionString = theConnectionSt ring;
connection.Open ();
DbCommand command = factory.CreateC ommand();
command.Connect ion = connection; command.Command Type =
CommandType.Tex t;
command.Command Text = "print 'hi mum';select 1 as somecolumn;prin t
'hi again'";
DbDataReader reader = command.Execute Reader();
reader.Close();
}
void Chapter4_InfoMe ssage(object sender, SqlInfoMessageE ventArgs e)
{
string message = e.Message;
}
Comment