Hi,
I am using SQL Management objects to connect to SQL server. At the moment they contain simple "create table" commands for my example.
I run this code twice on purpose to cause an error for "table already exists".
However my events below are not getting triggered.
Anyone got any ideas, how I can get hold of this message in my code other then changing the ExecutionType to stop on errors causing exceptions ( which I dont want to do, I want to continue)
My Code:
public void executeSomeSQL() {
FileInfo file = new FileInfo(@"\c:\sqlcommands.sql");
string script = file.OpenText().ReadToEnd();
SqlConnection conn = new SqlConnection(sqlConnectionString);
conn.InfoMessage +=new SqlInfoMessageEventHandler(conn_InfoMessage);
Server server = new Server(new ServerConnection(conn));
server.ConnectionContext.InfoMessage += new SqlInfoMessageEventHandler(ConnectionContext_InfoMessage);
server.ConnectionContext.ExecuteNonQuery(script,ExecutionTypes.ContinueOnError);
MessageBox.Show("All Done");
}
Events:-
public void conn_InfoMessage(object sender, SqlInfoMessageEventArgs e)
{
textBox3.Text += "1:"+DateTime.Now.ToString();
}
public void ConnectionContext_InfoMessage(object sender, SqlInfoMessageEventArgs e)
{
textBox3.Text += "2:" + DateTime.Now.ToString();
}
Many thanks in advance,
J