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

4 posts, 0 answers
  1. Miika
    Miika avatar
    28 posts
    Member since:
    Jun 2012

    Posted 09 Apr 2013 Link to this post

    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
  2. Damyan Bogoev
    Admin
    Damyan Bogoev avatar
    581 posts

    Posted 11 Apr 2013 Link to this post

    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 >>
  3. DevCraft banner
  4. David Thompson
    David Thompson avatar
    29 posts
    Member since:
    Feb 2010

    Posted 18 Jul 2013 Link to this post

    Can you please provide an example of how that works?
  5. Damyan Bogoev
    Admin
    Damyan Bogoev avatar
    581 posts

    Posted 23 Jul 2013 Link to this post

    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.
Back to Top