This is a migrated thread and some comments may be shown as answers.

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

2 Answers 2640 Views
Data Access Free Edition
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Dan
Top achievements
Rank 1
Dan asked on 17 Aug 2016, 08:34 PM

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 Answers, 1 is accepted

Sort by
0
Kaloyan Nikolov
Telerik team
answered on 19 Aug 2016, 10:36 AM
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.
0
Dan
Top achievements
Rank 1
answered on 13 Jan 2017, 01:18 PM

We are having the same issue.  Were you ever able to resolve this?  If so, would you mind sharing what you did?

I don't understand the answer from Telerikto create "short living context instances" because of multiple threads.  I don't know what a short living context instance means.  Could you share some code?  We don't have multiple threads, so I'm not sure where the problem is occurring or what to change.

Tags
Data Access Free Edition
Asked by
Dan
Top achievements
Rank 1
Answers by
Kaloyan Nikolov
Telerik team
Dan
Top achievements
Rank 1
Share this question
or