
Untitled
By: a guest on
Jun 17th, 2012 | syntax:
None | size: 1.38 KB | hits: 10 | expires: Never
How to catch SQLException in C#?
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.
catch (Exception ex)
{
ErrorFlag = true;
//ex.Source.ToString();
e2dInsertAndGenerateErrorLog(ex.InnerException.Message.ToString(), FileName, "CHECKINAPPLY", PathName, "ErrorLog.Err");
}
The select list for the INSERT statement contains more items than the insert list.
Msg 121, Level 15, State 1, Procedure test_sp_syntaxtext, Line 124
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);
catch (SqlException ex)
{
for (int i = 0; i < ex.Errors.Count; i++)
{
errorMessages.Append("Index #" + i + "n" +
"Message: " + ex.Errors[i].Message + "n" +
"LineNumber: " + ex.Errors[i].LineNumber + "n" +
"Source: " + ex.Errors[i].Source + "n" +
"Procedure: " + ex.Errors[i].Procedure + "n");
}
Console.WriteLine(errorMessages.ToString());
}
catch (SqlException ex) { ... }