title: c# and SMO - Get Message output such as "Table already exists" for logging
body: <p>I am using SQL Management objects to connect to SQL server. At the moment they contain simple "create table" commands for my example.</p>
  
  <p>I run this code twice on purpose to cause an error for "table already exists".</p>
  
  <p>However my events below are not getting triggered.  </p>
  
  <p>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)</p>
  
  <p>My Code:</p>
  
  <pre><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");
  }
  </code></pre>
  
  <p>Events:-</p>
  
  <pre><code>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();
  }
  </code></pre>