Transaction Timeout.

Posts   
 
    
MGrassman
User
Posts: 7
Joined: 11-Dec-2006
# Posted on: 05-Aug-2008 22:40:08   

I have the following code. That always causes a timeout issue as if it's waiting for the the db to be ready to read. The time it takes to execute is less then 2 seconds without transactions. I would prefer to use the serialize level but I can't even get this to work.

I have also tried this without the using statement.

SQL 2005 LLBLGen 2.0

Please help as this is urgent.

Thanks,


bool success = true;
        
        Transaction transactionManager = new Transaction(IsolationLevel.ReadUncommitted, "MarkLotComplete1");
        try
        {
            decimal settlementPrice = 0;
            ItLotsEntity e = new ItLotsEntity(lotNumber);
            e.ReceivedDate = DateTime.Now;
            e.Received = 1;
            transactionManager.Add(e);
            e.Save();
            
            ItSkidsEntity skidEnt;
            ItTransactionProcessEntity newEnt;
            using (ItTransactionProcessCollection col = new ItTransactionProcessCollection())
            {
                //ItTransactionProcessCollection newCol = new ItTransactionProcessCollection();
                PredicateExpression f = new PredicateExpression(ItTransactionProcessFields.LotNumber == lotNumber);
                col.GetMulti(f);
                foreach (ItTransactionProcessEntity OldTrans in col)
                {
                    OldTrans.TransactionDateExit = DateTime.Now;
                    if (OldTrans.CategoryID.HasValue)
                    {
                        settlementPrice = getSettlementPrice(OldTrans.ParentTransactionID.Value, Convert.ToInt32(OldTrans.CurrentProcessStepID), OldTrans.NextProcessStepID.Value, OldTrans.CategoryID.Value, OldTrans.LotNumber.Value);
                        if (settlementPrice != -99999)
                        {
                            OldTrans.Settlement = settlementPrice;
                        }
                    }
                    transactionManager.Add(OldTrans);
                    OldTrans.Save();
                    //transactionManager.Add(newCol);
                    //newCol.Items.Add(OldTrans);
                    newEnt = new ItTransactionProcessEntity();
                    skidEnt = new ItSkidsEntity();
                    newEnt.LotNumber = OldTrans.LotNumber;
                    newEnt.ParentTransactionID = OldTrans.TransactionID;
                    newEnt.TransactionDateEntered = DateTime.Now;
                    if (OldTrans.NextProcessStepID.HasValue)
                    {
                        newEnt.CurrentProcessStepID = OldTrans.NextProcessStepID.Value;
                    }
                    newEnt.CategoryID = OldTrans.CategoryID;
                    transactionManager.Add(newEnt);
                    newEnt.Save();

                    skidEnt.TransactionID = newEnt.TransactionID;
                    transactionManager.Add(skidEnt);
                    skidEnt.Save();
                }
            }
            //transactionManager.Add(newCol);
            //newCol.SaveMulti();

            transactionManager.Commit();
            transactionManager.Dispose();
            
        }
        catch (Exception e)
        {
            
            transactionManager.Rollback();
            transactionManager.Dispose();
            //throw new Exception(e.Message);
            success = false;
        }
        return success;

Thanks,

Michael

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 06-Aug-2008 10:56:00   

col.GetMulti(f);

As a rule of thumb, don't read inside a transaction.

Please try the following code:

        bool success = true;
        decimal settlementPrice = 0;
        ItLotsEntity e = new ItLotsEntity(lotNumber);
        e.ReceivedDate = DateTime.Now;
        e.Received = 1;

        ItSkidsEntity skidEnt;
        ItTransactionProcessEntity newEnt;
        ItTransactionProcessCollection col = new ItTransactionProcessCollection();
        //ItTransactionProcessCollection newCol = new ItTransactionProcessCollection();
        PredicateExpression f = new PredicateExpression(ItTransactionProcessFields.LotNumber == lotNumber);
        col.GetMulti(f);
        
        Transaction transactionManager = new Transaction(IsolationLevel.ReadUncommitted, "MarkLotComplete1");
        try
        {
                transactionManager.Add(e);
                e.Save();
            
                foreach (ItTransactionProcessEntity OldTrans in col)
                {
                    OldTrans.TransactionDateExit = DateTime.Now;
                    if (OldTrans.CategoryID.HasValue)
                    {
                        settlementPrice = getSettlementPrice(OldTrans.ParentTransactionID.Value, Convert.ToInt32(OldTrans.CurrentProcessStepID), OldTrans.NextProcessStepID.Value, OldTrans.CategoryID.Value, OldTrans.LotNumber.Value);
                        if (settlementPrice != -99999)
                        {
                            OldTrans.Settlement = settlementPrice;
                        }
                    }
                    transactionManager.Add(OldTrans);
                    OldTrans.Save();
                    //transactionManager.Add(newCol);
                    //newCol.Items.Add(OldTrans);
                    newEnt = new ItTransactionProcessEntity();
                    skidEnt = new ItSkidsEntity();
                    newEnt.LotNumber = OldTrans.LotNumber;
                    newEnt.ParentTransactionID = OldTrans.TransactionID;
                    newEnt.TransactionDateEntered = DateTime.Now;
                    if (OldTrans.NextProcessStepID.HasValue)
                    {
                        newEnt.CurrentProcessStepID = OldTrans.NextProcessStepID.Value;
                    }
                    newEnt.CategoryID = OldTrans.CategoryID;
                    transactionManager.Add(newEnt);
                    newEnt.Save();

                    skidEnt.TransactionID = newEnt.TransactionID;
                    transactionManager.Add(skidEnt);
                    skidEnt.Save();
                }
            //transactionManager.Add(newCol);
            //newCol.SaveMulti();

            transactionManager.Commit();
            transactionManager.Dispose();
            
        }
        catch (Exception e)
        {
            
            transactionManager.Rollback();
            transactionManager.Dispose();
            //throw new Exception(e.Message);
            success = false;
        }
        return success;
MGrassman
User
Posts: 7
Joined: 11-Dec-2006
# Posted on: 07-Aug-2008 16:41:53   

Thanks for your suggestion. I after altering the code to what you have provided I am still getting the same error.

Are there any other suggestions?

Thanks,

arschr
User
Posts: 894
Joined: 14-Dec-2003
# Posted on: 07-Aug-2008 19:53:53   

can you see what is happening in the database using sp_who2 (to see if you are blocked) or by running profiler and capturing the sql that is being run?