在这里,我试图使用SMO Ojects.In Sqlserver中的innerexception来捕获sql异常。我得到了以下错误消息
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);发布于 2011-05-11 18:40:21
使用SQLException。
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());
}发布于 2011-05-11 18:40:23
catch (SqlException ex) { ... }发布于 2011-05-11 18:41:31
看看你在http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlexception.aspx上找到的属性
您将需要捕获SqlException,而不只是任何异常。
https://stackoverflow.com/questions/5962884
复制相似问题