c***@gmail.com
2016-05-13 14:01:50 UTC
I am using the InfoMessageHandler to capture PRINT statements during Data Adapter's Fill execution. But I don't get any PRINT out put in C# after I have executed the SELECT. Please see code below: Can somebody help please?
this._txtPRINT.Clear();
string sSql = @"
PRINT '-------------------------------'
PRINT '-- START -- '
PRINT '-------------------------------'
SELECT GETDATE()
PRINT '-------------------------------'
PRINT '-- END -- '
PRINT '-------------------------------'";
SqlCommand oCmd = new SqlCommand(sSql, this.GetConnection());
oCmd.Connection.InfoMessage += this.Query_SqlInfoMessage;
SqlDataAdapter oAD = new SqlDataAdapter(oCmd);
DataTable oTable = new DataTable();
oAD.Fill(oTable);
I don't get the PRINT statement output after the SELECT GETDATE().
private void Query_SqlInfoMessage(object sender, SqlInfoMessageEventArgs e)
{
try
{
foreach (var oItem in e.Errors)
this._txtPRINT.Text += Environment.NewLine + e.Message;
}
catch (Exception oEx)
{
MessageBox.Show(oEx.Message);
}
}
Please note that I am developing a framework for executing queries and being able to capture all PRINT statements is crucial for me. I have no control over the SQL so I can't for example raise error instead of PRINT.
this._txtPRINT.Clear();
string sSql = @"
PRINT '-------------------------------'
PRINT '-- START -- '
PRINT '-------------------------------'
SELECT GETDATE()
PRINT '-------------------------------'
PRINT '-- END -- '
PRINT '-------------------------------'";
SqlCommand oCmd = new SqlCommand(sSql, this.GetConnection());
oCmd.Connection.InfoMessage += this.Query_SqlInfoMessage;
SqlDataAdapter oAD = new SqlDataAdapter(oCmd);
DataTable oTable = new DataTable();
oAD.Fill(oTable);
I don't get the PRINT statement output after the SELECT GETDATE().
private void Query_SqlInfoMessage(object sender, SqlInfoMessageEventArgs e)
{
try
{
foreach (var oItem in e.Errors)
this._txtPRINT.Text += Environment.NewLine + e.Message;
}
catch (Exception oEx)
{
MessageBox.Show(oEx.Message);
}
}
Please note that I am developing a framework for executing queries and being able to capture all PRINT statements is crucial for me. I have no control over the SQL so I can't for example raise error instead of PRINT.