Hi,
I am trying to use InfoMessage event associated with connection object.The command I am trying to execute is throwing error because it does not found the table with name a under my pubs database.
In that case the connection_InfoMessage event must be fired but in my case I am getting nothing under this event.
Why this event is not firing?
Please do correct me if I am taking it in wrong approach.
Regards,
Vishal Pawar
Code:
//**********************Sample code***************************
private void GetData()
{
SqlConnection connection=new SqlConnection();
connection.ConnectionString=ConfigurationSettings.AppSettings["ConStr"].ToString();
connection.InfoMessage+=new SqlInfoMessageEventHandler(connection_InfoMessage);
connection.Open();
try{
SqlCommand command=new SqlCommand("select * from a",connection);
SqlDataReader dataReader=command.ExecuteReader();
connection.Close();
}
catch(Exception)
{
}
}
public void connection_InfoMessage(object src,System.Data.SqlClient.SqlInfoMessageEventArgs e)
{
foreach(SqlError err in e.Errors)
{
Response.Write("<br>Line number:"+err.LineNumber);
Response.Write(" nbsp;Message:"+err.Message);
}
}