title: How to catch SQLException in C#?
body: <p>Here i tried to catch the sql exception using innerexception in SMO Ojects.In Sqlserver
  i am getting this error message </p>
  
  <pre><code>Msg 121, Level 15, State 1, Procedure test_sp_syntaxtext, Line 124
  The select list for the INSERT statement contains more items than the insert list.
  </code></pre>
  
  <p>But by using this code</p>
  
  <pre><code>catch (Exception ex)
            {
             ErrorFlag = true;
             //ex.Source.ToString();
             e2dInsertAndGenerateErrorLog(ex.InnerException.Message.ToString(), FileName, "CHECKINAPPLY", PathName, "ErrorLog.Err");
            }
  </code></pre>
  
  <p>i am getting this </p>
  
  <pre><code>The select list for the INSERT statement contains more items than the insert list.
  </code></pre>
  
  <p>I need to cache this line also</p>
  
  <pre><code>Msg 121, Level 15, State 1, Procedure test_sp_syntaxtext, Line 124
  </code></pre>
  
  <p>Any Suggestion?    </p>
  
  <p>EDIT:</p>
  
  <pre><code>  StreamReader str = new StreamReader(FiletextBox.Text.ToString());
    string script = str.ReadToEnd();
    str.Dispose();
    SqlConnection conn = new SqlConnection("Data Source=xx;database=xxx;User id=sx;Password=xxxx");
    Server server = new Server(new ServerConnection(conn));
    server.ConnectionContext.ExecuteNonQuery(script);
  </code></pre>