执行 SP ASP.NET C# 时出错
public DataTable RunProc(String sProcName, SqlParameter[] arrParams)
{
string sClassName = "DBAccess.RunProc";
SqlConnection objSqlConnection = null;
try
{
objSqlConnection = (SqlConnection)OpenConnection();
string sLogMessage="Executing Stored Procedure: ["+ sProcName +"] with Parameters ";
foreach(SqlParameter objParameter in arrParams)
{
sLogMessage+=objParameter.ParameterName+" = ";
sLogMessage+=objParameter.Value+" ";
}
logger.Logns(LogLevel.TraceDetail,sClassName," ",sLogMessage);
SqlCommand objSqlCommand = CreateCommand(sProcName, arrParams,objSqlConnection,null);
objSqlCommand.CommandTimeout=300;
SqlDataAdapter objSQLDataAdapter = new SqlDataAdapter(objSqlCommand);
DataSet objDataSet = new DataSet();
objSQLDataAdapter.Fill(objDataSet);
this.CloseConnection(objSqlConnection);
logger.Logns(LogLevel.TraceDetail,sClassName," ","Success Executing Stored Procedure: ["+ sProcName +"]");
this.CloseConnection(objSqlConnection);
if( objDataSet.Tables.Count>0)
{
return objDataSet.Tables[0];
}
else
{
return null;
}
//SqlParameter p= new SqlParameter("PACCOUNTNUM", IBM.Data.DB2.DB2Type.VarChar, 17, System.Data.ParameterDirection.Input, true, ((System.Byte)(0)), ((System.Byte)(0)), "", System.Data.DataRowVersion.Current, null);
}
catch(Exception Ex)
{
logger.Logns(LogLevel.TraceDetail,sClassName," ","Error Executing Stored Procedure: ["+ Ex.ToString() +"]");
this.CloseConnection(objSqlConnection);
throw(new Exception(Ex.ToString()));
}
}
上面提到的代码在我们的生产环境中成功执行,但是突然我们开始在日志中收到错误
11/04/2011 09:42:46 AM|TraceDetail
|DBAccess.RunProc
| |错误 执行存储过程: [System.Threading.ThreadAbortException: 线程被中止。在 SNINativeMethodWrapper.SNIPacketGetConnection(IntPtr 包)在 System.Data.SqlClient.TdsParserStateObject.ProcessSniPacket(IntPtr 数据包,UInt32 错误)位于 System.Data.SqlClient.TdsParserStateObject.ReadSni(DbAsyncResult 异步结果、TdsParserStateObject 状态对象)在 System.Data.SqlClient.TdsParserStateObject.ReadPacket(Int32 预计字节数)在 System.Data.SqlClient.TdsParserStateObject.ReadBuffer() 在 System.Data.SqlClient.TdsParserStateObject.ReadByte() 在 System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior、SqlCommand cmdHandler、 SqlDataReader数据流, 批量复制简单结果集 批量复制处理程序、TdsParserStateObject 状态对象)在 System.Data.SqlClient.SqlDataReader.ConsumeMetaData() 在 System.Data.SqlClient.SqlDataReader.get_MetaData() 在 System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds,RunBehavior runBehavior,字符串 重置选项字符串)在 System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, 布尔返回流、布尔异步)
在 System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, 布尔returnStream,字符串方法, DbAsyncResult 结果)位于 System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, 布尔返回Stream、字符串方法)
在 System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior 行为,字符串方法)位于 System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior 行为)在 System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior 行为)在 System.Data.Common.DbDataAdapter.FillInternal(数据集 数据集、DataTable[] 数据表、Int32 startRecord,Int32 maxRecords,字符串 srcTable、IDbCommand 命令、 CommandBehavior 行为) at System.Data.Common.DbDataAdapter.Fill(数据集 数据集,Int32 开始记录,Int32 maxRecords,字符串 srcTable, IDbCommand 命令、CommandBehavior 行为)在 System.Data.Common.DbDataAdapter.Fill(数据集 数据集)位于 GDCIEngine.Data.PrismDb.DBAccess.RunProc(字符串 sProcName, SqlParameter[] arrParams)]
上面提到的代码用于由表示层调用的 Web 服务中,在表示层上我碰巧收到 HTTP 超时,但是在实际托管服务的后端上,一旦我就打印上述异常在后端计算机上执行 iisreset,一切都开始按预期工作,此错误时不时地出现,iisreset 是我想出的唯一解决方案来应对它,在这方面的任何帮助将不胜感激,
谢谢 问候 阿泽姆
public DataTable RunProc(String sProcName, SqlParameter[] arrParams)
{
string sClassName = "DBAccess.RunProc";
SqlConnection objSqlConnection = null;
try
{
objSqlConnection = (SqlConnection)OpenConnection();
string sLogMessage="Executing Stored Procedure: ["+ sProcName +"] with Parameters ";
foreach(SqlParameter objParameter in arrParams)
{
sLogMessage+=objParameter.ParameterName+" = ";
sLogMessage+=objParameter.Value+" ";
}
logger.Logns(LogLevel.TraceDetail,sClassName," ",sLogMessage);
SqlCommand objSqlCommand = CreateCommand(sProcName, arrParams,objSqlConnection,null);
objSqlCommand.CommandTimeout=300;
SqlDataAdapter objSQLDataAdapter = new SqlDataAdapter(objSqlCommand);
DataSet objDataSet = new DataSet();
objSQLDataAdapter.Fill(objDataSet);
this.CloseConnection(objSqlConnection);
logger.Logns(LogLevel.TraceDetail,sClassName," ","Success Executing Stored Procedure: ["+ sProcName +"]");
this.CloseConnection(objSqlConnection);
if( objDataSet.Tables.Count>0)
{
return objDataSet.Tables[0];
}
else
{
return null;
}
//SqlParameter p= new SqlParameter("PACCOUNTNUM", IBM.Data.DB2.DB2Type.VarChar, 17, System.Data.ParameterDirection.Input, true, ((System.Byte)(0)), ((System.Byte)(0)), "", System.Data.DataRowVersion.Current, null);
}
catch(Exception Ex)
{
logger.Logns(LogLevel.TraceDetail,sClassName," ","Error Executing Stored Procedure: ["+ Ex.ToString() +"]");
this.CloseConnection(objSqlConnection);
throw(new Exception(Ex.ToString()));
}
}
The above mentioned code executes successfully in our production enviroment however all of the sudden we start getting Error in our logs
11/04/2011 09:42:46 AM|TraceDetail
|DBAccess.RunProc
| |Error
Executing Stored Procedure:
[System.Threading.ThreadAbortException:
Thread was being aborted. at
SNINativeMethodWrapper.SNIPacketGetConnection(IntPtr
packet) at
System.Data.SqlClient.TdsParserStateObject.ProcessSniPacket(IntPtr
packet, UInt32 error) at
System.Data.SqlClient.TdsParserStateObject.ReadSni(DbAsyncResult
asyncResult, TdsParserStateObject
stateObj) at
System.Data.SqlClient.TdsParserStateObject.ReadPacket(Int32
bytesExpected) at
System.Data.SqlClient.TdsParserStateObject.ReadBuffer()
at
System.Data.SqlClient.TdsParserStateObject.ReadByte()
at
System.Data.SqlClient.TdsParser.Run(RunBehavior
runBehavior, SqlCommand cmdHandler,
SqlDataReader dataStream,
BulkCopySimpleResultSet
bulkCopyHandler, TdsParserStateObject
stateObj) at
System.Data.SqlClient.SqlDataReader.ConsumeMetaData()
at
System.Data.SqlClient.SqlDataReader.get_MetaData()
at
System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader
ds, RunBehavior runBehavior, String
resetOptionsString) at
System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior
cmdBehavior, RunBehavior runBehavior,
Boolean returnStream, Boolean async)
at
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior
cmdBehavior, RunBehavior runBehavior,
Boolean returnStream, String method,
DbAsyncResult result) at
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior
cmdBehavior, RunBehavior runBehavior,
Boolean returnStream, String method)
at
System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior
behavior, String method) at
System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior
behavior) at
System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior
behavior) at
System.Data.Common.DbDataAdapter.FillInternal(DataSet
dataset, DataTable[] datatables, Int32
startRecord, Int32 maxRecords, String
srcTable, IDbCommand command,
CommandBehavior behavior) at
System.Data.Common.DbDataAdapter.Fill(DataSet
dataSet, Int32 startRecord, Int32
maxRecords, String srcTable,
IDbCommand command, CommandBehavior
behavior) at
System.Data.Common.DbDataAdapter.Fill(DataSet
dataSet) at
GDCIEngine.Data.PrismDb.DBAccess.RunProc(String
sProcName, SqlParameter[]
arrParams)]
The above mentioned code is used in a Web service which is called by presentation layer on the presentation layer i happen to recive HTTP Timedout however on the backend where the service is actually hosted the above mentioned exception is getting printed as soon as i do an iisreset on backend machine every thing start working as expected this error is showing up every now and then and iisreset being the only solution i have come up to cope up with it any help in this regard would be highly appreciated
Thanks
Regards
Azeem
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您收到 System.Threading.ThreadAbortException 异常。这是一个典型的异常由 Response.End、Response.Redirect 或 Server.Transfer 引起。
您的代码中的某些内容导致您尝试重定向。可能是数据库连接丢失了?
不幸的是,解决这个问题的唯一方法是调试它或尝试自己修复它。
如果缺少调试(因为它是生产环境),您可以尝试在整个函数中以特定的时间间隔抛出日志语句,以尝试缩小问题所在的范围。例如,
等等。这可能是追踪此问题的唯一方法。
You're getting the System.Threading.ThreadAbortException exception. It's a classic exception caused by Response.End, Response.Redirect, or Server.Transfer.
Something in your code is code is causing you to attempt to redirect. Possibly a lost database connection?
Unfortunately, the only way to fix this is to debug it or to try to fix it yourself.
Short of debugging (since it's production), you could try throwing log statements in at specific intervals throughout the function to try to narrow down where the problem is. e.g.
etc. That might be the only way to track this down.