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

May not call commit,rollback and begin in managed transaction environment

3 Answers 107 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Miika
Top achievements
Rank 1
Miika asked on 09 Apr 2013, 06:32 AM
Good morning,

I am getting a strange error when using an SQL Server stored procedure through Telerik ORM all surrounded by a TransactionScope. Everything works fine up until I make a call to a stored procedure (It is just a data retrieval stored procedure, nothing is being inserted, updated or deleted). The error itself is shown below, and I have not been able to find any information on what might be causing it. The code also works if there is no TransactionScope.

Simplified version of code (in pseudocode-ish):


using (TransactionScope scope = new TransactionScope())
{
    // Make calls through OpenAccess ORM, includes inserts/updates. This all works.
    orm.FlushChanges();
    orm.SaveChanges();

    // Make call to stored procedure. This causes exception.
   
    scope.Complete();
}


1: Description: May not call commit,rollback and begin in managed transaction environment.
1: Stack Trace: at Telerik.OpenAccess.SPI.Backends.ThrowException(Exception e)
1: at OpenAccessRuntime.ExceptionWrapper.Throw()
1: at OpenAccessRuntime.DataObjects.OpenAccessPersistenceManagerImp.handleException(Exception x, Boolean needsRollback)
1: at OpenAccessRuntime.DataObjects.OpenAccessPersistenceManagerImp.GetConnection(Boolean& isNew)
1: at OpenAccessRuntime.DataObjects.UnsynchronizedPMProxy.GetConnection(Boolean& isNew)
1: at OpenAccessRuntime.ObjectScope.GetConnection(Boolean& isNew)
1: at Telerik.OpenAccess.OpenAccessContextBase.GetConnection(Boolean& isNew)
1: at Telerik.OpenAccess.OpenAccessContextBase.ExecuteQuery[T](String commandText, CommandType commandType, DbParameter[] parameters)
1: at Rediteq.CampusPro.DataAccess.CampusProEntitiesModel.UspHaeElementinVastuuhenkilo

3 Answers, 1 is accepted

Sort by
0
Damyan Bogoev
Telerik team
answered on 11 Apr 2013, 04:09 PM
Hello Miika,

 
The error arises because the given stored procedure is being executed using a managed transaction, which is handled by the OpenAccess transaction provider.
You could try changing the provider to automatic using the following approach:
- expose the underlying IObjectScope for the context by introducing a property for your context class, which calls the GetScope() method;
- now you could modify the Scope.TransactionProvider to Automatic;

Hope that helps.

Regards,
Damyan Bogoev
the Telerik team
Using Encrypted Connection Strings with Telerik OpenAccess ORM. Read our latest blog article >>
0
David Thompson
Top achievements
Rank 2
answered on 18 Jul 2013, 10:06 PM
Can you please provide an example of how that works?
0
Damyan Bogoev
Telerik team
answered on 23 Jul 2013, 10:09 AM
Hello David,

I have prepared a sample application, which demonstrates how to handle the transaction provider and achieve this goal.

Hope that helps.

Regards,
Damyan Bogoev
Telerik
OpenAccess ORM Q2 2013 brings you a more powerful code generation and a unique Bulk Operations support with LINQ syntax. Check out the list of new functionality and improvements shipped with this release.
Tags
General Discussions
Asked by
Miika
Top achievements
Rank 1
Answers by
Damyan Bogoev
Telerik team
David Thompson
Top achievements
Rank 2
Share this question
or