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 asyncResult,TdsParserStateObject stateObj)at System.Data.SqlClient.TdsParserStateObject.ReadPacket(的Int32 bytesExpected)at System.Data.SqlClient.TdsParserStateObject.ReadBuffer() 在 System.Data.SqlClient.TdsParserStateObject.ReadByte() 在 System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior,SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler,TdsParserStateObject stateObj)at System.Data.SqlClient.SqlDataReader.ConsumeMetaData() 在 System.Data.SqlClient.SqlDataReader.get_MetaData() 在 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)
在 System.Data.SqlClient.SqlCommand.RunExecuteReader(的CommandBehavior cmdBehavior,RunBehavior runBehavior, Boolean returnStream,String方法, DbAsyncResult结果)at System.Data.SqlClient.SqlCommand.RunExecuteReader(的CommandBehavior cmdBehavior,RunBehavior runBehavior, Boolean returnStream,String method)
在 System.Data.SqlClient.SqlCommand.ExecuteReader(的CommandBehavior 行为,String方法)at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(的CommandBehavior 行为) System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(的CommandBehavior 行为) System.Data.Common.DbDataAdapter.FillInternal(数据集 数据集,DataTable [] datatables,Int32 startRecord,Int32 maxRecords,String srcTable,IDbCommand命令, CommandBehavior行为)at System.Data.Common.DbDataAdapter.Fill(数据集 dataSet,Int32 startRecord,Int32 maxRecords,String srcTable, IDbCommand命令,CommandBehavior 行为) System.Data.Common.DbDataAdapter.Fill(数据集 dataSet)at GDCIEngine.Data.PrismDb.DBAccess.RunProc(字符串 sProcName,SqlParameter [] arrParams)]
上面提到的代码用于Web服务,它由表示层上的表示层调用我碰巧重新发送HTTP Timedout但是在实际托管服务的后端上面,上面提到的异常会立即打印出来在后端机器上做一个iisreset每件东西都按预期开始工作,这个错误时不时出现,iisreset是唯一能解决这个问题的解决方案,在这方面的任何帮助都将受到高度赞赏
由于 问候 Azeem
答案 0 :(得分:0)
您正在获取System.Threading.ThreadAbortException异常。这是一个经典例外caused by Response.End, Response.Redirect, or Server.Transfer。
代码中的某些内容是代码导致您尝试重定向。可能是丢失的数据库连接?
不幸的是,解决此问题的唯一方法是调试它或尝试自己修复它。
如果没有调试(因为它正在生产),你可以尝试在整个函数中以特定的时间间隔抛出日志语句,以尝试缩小问题所在的范围。 e.g。
logger.Logns(LogLevel.TraceDetail,sClassName," ","Trace point 1")
... do some stuff ...
logger.Logns(LogLevel.TraceDetail,sClassName," ","Trace point 2")
... do some more stuff ...
logger.Logns(LogLevel.TraceDetail,sClassName," ","Trace point 1")
等。这可能是追踪此问题的唯一方法。