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

How do I fix “new transaction is not allowed” error when using Telerik Open Access?

2 Answers 153 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 18 Jan 2017, 07:37 PM

We have a asp.net MVC application that uses Telerik Open Access. We're having all kinds of problems just saving data once we put it into production. Telerik no longer supports Open Access, so we can't get any help from them, but we're supposed to be going live right now and don't have the budgeted hours to change now. Can someone give me some suggestions on how to get around these problems?

We're getting the same errors when updating and inserting records, but these problems don't always occur. I never get these errors running the solution from Visual Studio on my computer or once the project is deployed to our testing server. On the production server, when several users are using the application, we start to see errors.

Example code would be this insert function:

public void CreateAttachments(tblCoDoc obj){
try{
         dat.Add(obj);        
         dat.SaveChanges();
}
catch (Exception exception){throw exception;}}

and this update function:

public void UpdateWorkOrderApprGen(tblWorkOrder obj){
    var context = new KoorsenOpenAccessContext();
    var upd =(from workOrder in dat.tblWorkOrders
            where workOrder.WorkOrderId == obj.WorkOrderIdselect workOrder
        ).FirstOrDefault();
 
if (
    upd != null){            
            upd.ReferenceNumber = obj.ReferenceNumber;
            upd.CustomerContract = obj.CustomerContract;            
            upd.VendorContract = obj.VendorContract;            
            upd.DateResolved = obj.DateResolved;
 
try{                
     context.SaveChanges();
}
catch (Exception ex){throw ex;}}}

In both cases, those methods are in a class called Repository. There is a private variable defined for this class (KOpenAccessContext is the class defined in the project implementing a OpenAccessContext class):

private static KOpenAccessContext dat = null;

and then in the Repository constructor, that private variable is assigned to a new KOpenAccessContext:

dat = new KoorsenOpenAccessContext();

The error message we're getting is

Telerik.OpenAccess.Exceptions.DataStoreException: Telerik.OpenAccess.RT.sql.SQLException: New transaction is not allowed because there are other threads running in the session.

 

This post suggests the problem is from the save being in a for loop, which is not the case.

The 3rd answer down suggests putting the code in a using transaction and using context blocks; I get this error:

Telerik.OpenAccess.OpenAccessException: System.InvalidOperationException: This SqlTransaction has completed; it is no longer usable.<br>

 

I found this post suggesting that I create "use short living context instances". To me that meant to create a new Open Access. I tried this and still got the "new transaction is not allowed" error:

 

public void CreateAttachments(tblCoDoc obj){
    try{var db = new KoorsenOpenAccessContext();        
    db.Add(obj);        
    db.SaveChanges();
}
catch (Exception exception){throw exception;}}

I'm really at a loss and I've got a client and boss looking to me for a solution. I'd love to know the cause of this (thinking it may be because there are multiple users), but what I really need is a solution. How can I get around this problem?

2 Answers, 1 is accepted

Sort by
0
Tom
Top achievements
Rank 1
answered on 19 Jan 2017, 02:47 PM

I feel your pain.  I have been floundering around with Data Access also and am certainly no expert.

It does seem to help to wrap your transactions with a "with".

public void CreateAttachmenst(tblCoDoc obj)
{
    

0
Tom
Top achievements
Rank 1
answered on 19 Jan 2017, 02:57 PM

I feel your pain.  I have been floundering around with Data Access also but when it works it works well.  I am no expert but try wrapping transactions in "using" statements so the db is disposed at the end.

public void Createattachmenst(tblCoDoc obj)
{
  using (var db = new KoorsenOpenAccessContext())
  {
    try
    {
     db.add(obj);
     db.saveChanges();
    }
    catch ...
  }
}

Tags
Data Access Free Edition
Asked by
Dan
Top achievements
Rank 1
Answers by
Tom
Top achievements
Rank 1
Share this question
or