October 12, 2004 at 12:09 pm
I'm trying to get progress messages from a long-running stored proc to a C# client program. In the proc, I use RAISERROR (@Message,10,1) WITH NOWAIT", and I've set up a SqlInfoMessageEventHandler. The handler gets all messages at the end of the proc, not as they are generated. However, when I run the proc from Query Analyzer, I get the messages right away. Is there any buffering going on that I can flush?
October 13, 2004 at 2:02 pm
I assume that you posted to the MS groups as well as I found this response there and it looked like your message as the request.
This is the current behavior of SqlConnection and OleDbConnection
InforMessage events. Query Analyzer uses ODBC so you might consider using
System.Data.Odbc.OdbcConnection instead if you need the InfoMessage returned
during proc execution. Note that this requires version 1.1 of the .Net
framework.
string connectionString =
"Driver={SQL Server};" +
"Server=MyServer;" +
"Database=MyDatabase;" +
"Trusted Connection=Yes";
try
{
using(OdbcConnection connection =
new OdbcConnection(connectionString))
{
connection.Open();
OdbcCommand command =
new OdbcCommand("MyProcedure", connection);
command.CommandType = CommandType.StoredProcedure;
connection.InfoMessage +=
new OdbcInfoMessageEventHandler(MyInfoMessageEventHandler);
command.ExecuteNonQuery();
connection.Close();
}
}
catch (OdbcException ex)
{
Console.WriteLine(ex.ToString());
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
--
Hope this helps.
Dan Guzman
SQL Server MVP
October 18, 2004 at 8:13 am
Thanks, Dan. I did not consider using ODBC. I instead wrote a little UPD sender program that I shell to on the SQL server to send a message, and a UDP receiver running in a seperate thread on the client.
Viewing 3 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply