Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 17th, 2012  |  syntax: None  |  size: 1.38 KB  |  hits: 10  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. How to catch SQLException in C#?
  2. Msg 121, Level 15, State 1, Procedure test_sp_syntaxtext, Line 124
  3. The select list for the INSERT statement contains more items than the insert list.
  4.        
  5. catch (Exception ex)
  6.           {
  7.            ErrorFlag = true;
  8.            //ex.Source.ToString();
  9.            e2dInsertAndGenerateErrorLog(ex.InnerException.Message.ToString(), FileName, "CHECKINAPPLY", PathName, "ErrorLog.Err");
  10.           }
  11.        
  12. The select list for the INSERT statement contains more items than the insert list.
  13.        
  14. Msg 121, Level 15, State 1, Procedure test_sp_syntaxtext, Line 124
  15.        
  16. StreamReader str = new StreamReader(FiletextBox.Text.ToString());
  17.   string script = str.ReadToEnd();
  18.   str.Dispose();
  19.   SqlConnection conn = new SqlConnection("Data Source=xx;database=xxx;User id=sx;Password=xxxx");
  20.   Server server = new Server(new ServerConnection(conn));
  21.   server.ConnectionContext.ExecuteNonQuery(script);
  22.        
  23. catch (SqlException ex)
  24.     {
  25.         for (int i = 0; i < ex.Errors.Count; i++)
  26.         {
  27.             errorMessages.Append("Index #" + i + "n" +
  28.                 "Message: " + ex.Errors[i].Message + "n" +
  29.                 "LineNumber: " + ex.Errors[i].LineNumber + "n" +
  30.                 "Source: " + ex.Errors[i].Source + "n" +
  31.                 "Procedure: " + ex.Errors[i].Procedure + "n");
  32.         }
  33.         Console.WriteLine(errorMessages.ToString());
  34.     }
  35.        
  36. catch (SqlException ex) { ... }