How can I retrieve a string generated by the PRINT t-sql command of SQL Server in my .net application
Example Microsoft SQl Server Management Studio :
How can I retrieve a string generated by the PRINT t-sql command of SQL Server in my .net application
Example Microsoft SQl Server Management Studio :
In order to retrieve these message, you can use the InfoMessage
event available on the SqlConnection
class.
using (SqlConnection conn = new SqlConnection("..."))
{
conn.InfoMessage += (sender, e) =>
{
Console.WriteLine($"{e.Source}-{e.Message}");
};
conn.Open();
using (SqlCommand command = new SqlCommand("PRINT 'Hello World'", conn))
{
command.ExecuteNonQuery();
}
}