How do I fix a "New transaction is not allowed" error is Telerik Open Access?

2 posts, 0 answers
  1. Dan
    Dan avatar
    7 posts
    Member since:
    Jul 2011

    Posted 17 Aug Link to this post

    I'm using Telerik Open Access to interface between my C#, asp.net MVC project and a SQL database. I started having a problem on a section that has been working fine. When I update a record in the database, every once in a while the record isn't updated. Added a try block to the SaveChanges command and found an error saying "New transaction is not allowed". I researched this error online, but found mostly comments relating to Entity Framework, not Telerik Open Access. I submitted a ticket to Telerik, but I know Open Access isn't supported by them so I don't expect a solution from them. Can someone explain how to fix this?

    Here's my code:

    public void UpdateWorkOrderGen(tblWorkOrder obj)
            {
     
                // ensure valid loc for this company
     
                int compId = int.Parse(obj.CompanyId.ToString());
     
                int locId = int.Parse(obj.LocationId.ToString());
     
                var locToUse = GetLocIdToUse(compId, locId);
     
                var upd = dat.tblWorkOrders.FirstOrDefault(itm => itm.WorkOrderId == obj.WorkOrderId);
     
                if (upd != null)
                {
                    upd.CompanyId = obj.CompanyId;
                    upd.LocationId = locToUse;
                    upd.AssignToCompany = obj.AssignToCompany;
                    upd.WorkOrderDate = obj.WorkOrderDate;
                    upd.ServiceType = obj.ServiceType;
                    upd.WorkOrderPriority = obj.WorkOrderPriority;
                    upd.WorkOrderStatus = obj.WorkOrderStatus;
                    upd.DateNeeded = obj.DateNeeded;
                    upd.ReferenceNumber = obj.ReferenceNumber;
                    upd.RequestedBy = obj.RequestedBy;
                    upd.ProblemDescription = CleanCtrlCharsFromText(obj.ProblemDescription);
                    upd.CustomerContract = obj.CustomerContract;
                    upd.VendorContract = obj.VendorContract;
                }
     
                try
                {
                    dat.SaveChanges();
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }

    And here is the error I'm getting:
    Telerik.OpenAccess.RT.sql.SQLException: New transaction is not allowed because there are other threads running in the session. ---> System.Data.SqlClient.SqlException: New transaction is not allowed because there are other threads running in the session. at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction) at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction) at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) at System.Data.SqlClient.TdsParser.TdsExecuteTransactionManagerRequest(Byte[] buffer, TransactionManagerRequestType request, String transactionName, TransactionManagerIsolationLevel isoLevel, Int32 timeout, SqlInternalTransaction transaction, TdsParserStateObject stateObj, Boolean isDelegateControlRequest) at System.Data.SqlClient.SqlInternalConnectionTds.ExecuteTransactionYukon(TransactionRequest transactionRequest, String transactionName, IsolationLevel iso, SqlInternalTransaction internalTransaction, Boolean isDelegateControlRequest) at System.Data.SqlClient.SqlInternalConnectionTds.ExecuteTransaction(TransactionRequest transactionRequest, String name, IsolationLevel iso, SqlInternalTransaction internalTransaction, Boolean isDelegateControlRequest) at System.Data.SqlClient.SqlInternalConnection.BeginSqlTransaction(IsolationLevel iso, String transactionName, Boolean shouldReconnect) at System.Data.SqlClient.SqlConnection.BeginTransaction(IsolationLevel iso, String transactionName) at System.Data.SqlClient.SqlConnection.BeginDbTransaction(IsolationLevel isolationLevel) at System.Data.Common.DbConnection.BeginTransaction(IsolationLevel isolationLevel) at OpenAccessRuntime.Intellitrace.BeginTransaction(DbConnection connection, IsolationLevel isolationLevel, String id) at Telerik.OpenAccess.Runtime.Logging.LoggingDbConnection.BeginDbTransaction(IsolationLevel isolationLevel) at System.Data.Common.DbConnection.BeginTransaction(IsolationLevel isolationLevel) at Telerik.OpenAccess.RT.Adonet2Generic.Impl.ConnectionImp.DefBeginTransaction() at Telerik.OpenAccess.RT.Adonet2Generic.Impl.Sql2005Factory.Telerik.OpenAccess.RT.Adonet2Generic.Impl.IADOFactory.BeginTransaction(ConnectionImp c) at Telerik.OpenAccess.RT.Adonet2Generic.Impl.ConnectionImp.begin() --- End of inner exception stack trace --- at Telerik.OpenAccess.RT.Adonet2Generic.Impl.ConnectionImp.begin() at OpenAccessRuntime.Relational.conn.PsPoolConnection.begin() at OpenAccessRuntime.Relational.RelationalStorageManager.obtainConnection(Boolean forWriting) at OpenAccessRuntime.Relational.RelationalStorageManager.generateUpdates(OID oid, Int32 index, ClassMetaData cmd, PersistGraph graph, Int32[] fieldNos, Boolean haveNewObjects, CharBuf s, BatchControlInfo batchControl, Boolean previousInserts) at OpenAccessRuntime.Relational.RelationalStorageManager.persistPass1(PersistGraph graph, BatchControlInfo batchControl)
  2. Kaloyan Nikolov
    Admin
    Kaloyan Nikolov avatar
    118 posts

    Posted 19 Aug Link to this post

    Hi Dan,

    Most probably the root cause of this issue is that you are using a single Context instance across multiple threads. In such case it happens that one of the threads is saving changes and there is open transaction at the moment when another one is trying to do the same. 

    I would suggest you to change your context instance management - the safest way is to use short living context instances within your methods. The Context instance is light weight so it will not affect the performance. 


    Regards,
    Kaloyan Nikolov
    Telerik by Progress
     
    Check out the latest announcement about Telerik Data Access vNext as a powerful framework able to solve core development problems.
  3. DevCraft banner
Back to Top