PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Hébergement serveur > comp.db.ms-sqlserver > odd SqlInfoMessageEventHandler problem (source code provided)
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
odd SqlInfoMessageEventHandler problem (source code provided)

Réponse
 
LinkBack Outils de la discussion
Vieux 05/11/2008, 12h25   #1
codefragment@googlemail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut odd SqlInfoMessageEventHandler problem (source code provided)

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"
connectionString="Integrated
Security=SSPI;database=Northwind;server=localhost; Connect Timeout=30;
Persist Security Info=False"
/>



private void ShowPrintStatements()
{
DbProviderFactory factory = SqlClientFactory.Instance;

ConnectionStringSettings settings =
ConfigurationManager.ConnectionStrings["Northwind"];
string theConnectionString = settings.ConnectionString;

DbConnection connection = factory.CreateConnection();
if (connection is SqlConnection)
{
((SqlConnection)connection).InfoMessage += new
SqlInfoMessageEventHandler(Chapter4_InfoMessage);
}

connection.ConnectionString = theConnectionString;
connection.Open();

DbCommand command = factory.CreateCommand();
command.Connection = connection; command.CommandType =
CommandType.Text;
command.CommandText = "print 'hi mum';select 1 as somecolumnrint
'hi again'";
DbDataReader reader = command.ExecuteReader();

reader.Close();
}

void Chapter4_InfoMessage(object sender, SqlInfoMessageEventArgs e)
{
string message = e.Message;
}
  Réponse avec citation
Vieux 05/11/2008, 23h47   #2
Erland Sommarskog
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: odd SqlInfoMessageEventHandler problem (source code provided)

codefragment@googlemail.com (codefragment@googlemail.com) writes:
> 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?


You need to call .NextResult to get the second message. To do thing
properly, you should always iterate over .NextResult until returns NULL,
to be sure that you get all results and messages.

--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Links for SQL Server Books Online:
SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx
SQL 2000: http://www.microsoft.com/sql/prodinf...ons/books.mspx

  Réponse avec citation
Vieux 07/11/2008, 09h19   #3
codefragment@googlemail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: odd SqlInfoMessageEventHandler problem (source code provided)

> You need to call .NextResult to get the second message. To do thing
> properly, you should always iterate over .NextResult until returns NULL,
> to be sure that you get all results and messages.


Yep, that did it, thanks :-)
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 02h22.


Édité par : vBulletin®
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,09026 seconds with 11 queries