1
votes
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

1
your code smells, if you use a singleton connection - what if 2 threads open connection? ... who will close it first ...user57508
Side note: Formatting the code just made me sleepy; use spaces for indentation (or spaces as tabs).Grant Thomas
OpenConnection always returns a new connection and it's not a singleton.zeemz
did you try to increase your sql timeout?user57508

1 Answers

0
votes

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.

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")

etc. That might be the only way to track this down.