Solved

Use Isolation level in LINQ

Posted on 2009-05-05
2
3,379 Views
Last Modified: 2013-11-11
I try to use isolation level with L2E, but I've this problem:

The transaction specified for TransactionScope has a different IsolationLevel than the value requested for the scope. Parameter name: transactionOptions.IsolationLevel

And I dont understand why.

This error is displayed when I call my dedicated method:
public static int insertDB(InsertDbDelegate methodThatWriteDB, IsolationLevel isoLevel, MasterPage senderPage)

    {

        int objectsAdded = 0;
 

        try

        {

            using (var scope = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions() { IsolationLevel = isoLevel }))

            {

                using (geststockEntities gse = new geststockEntities(cs_admin))

                {

                    methodThatWriteDB(gse);

                    objectsAdded = gse.SaveChanges();

                    if (objectsAdded == 0) throw new Exception();

                    scope.Complete();

                    gse.Connection.Close();

                    addUserMessage(senderPage, "Insertion OK");

                }

            }

        }

        catch (Exception ex)

        {

            addErrorMessage(senderPage, "Error when connecting to the database." + ex.Message);

        }
 

        return objectsAdded;

    }

Open in new window

0
Comment
Question by:Nargzul
2 Comments
 
LVL 42

Expert Comment

by:EugeneZ
ID: 24325574
please post an error that you got

also check if it is related to your problem:

https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=325381&wa=wsignin1.0
0
 
LVL 1

Accepted Solution

by:
Nargzul earned 0 total points
ID: 24326032
Interception de System.Data.EntityException
  Message="Échec du fournisseur sous-jacent sur Open."
  Source="System.Data.Entity"
  StackTrace:
       à System.Data.EntityClient.EntityConnection.OpenStoreConnectionIf(Boolean openCondition, DbConnection storeConnectionToOpen, DbConnection originalConnection, String exceptionCode, String attemptedOperation, Boolean& closeStoreConnectionOnFailure)
       à System.Data.EntityClient.EntityConnection.Open()
       à System.Data.Objects.ObjectContext.EnsureConnection()
       à System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)
       à System.Data.Objects.ObjectQuery`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator()
       à System.Linq.Enumerable.First[TSource](IEnumerable`1 source)
       à System.Data.Objects.ELinq.ObjectQueryProvider.<GetElementFunction>b__0[TResult](IEnumerable`1 sequence)
       à System.Data.Objects.ELinq.ObjectQueryProvider.ExecuteSingle[TResult](IEnumerable`1 query, Expression queryRoot)
       à System.Data.Objects.ELinq.ObjectQueryProvider.System.Linq.IQueryProvider.Execute[S](Expression expression)
       à System.Linq.Queryable.First[TSource](IQueryable`1 source)
       à pages_Default.makeLoan(geststockEntities gse) dans d:\WorkSpaces\geststock\GestStock2\pages\makeLoan.aspx.cs:ligne 169
       à QueryHelper.insertDB(InsertDbDelegate methodThatWriteDB, IsolationLevel isoLevel, MasterPage senderPage) dans d:\WorkSpaces\geststock\GestStock2\App_Code\QueryHelper.cs:ligne 157
  InnerException: System.Transactions.TransactionManagerCommunicationException
       Message="L'accès réseau de MSDTC (Distributed Transaction Manager) a été désactivé. Activez DTC pour l'accès réseau dans la configuration de sécurité de MSDTC à l'aide de l'outil administratif des services de composants."
       Source="System.Transactions"
       StackTrace:
            à System.Transactions.Oletx.OletxTransactionManager.ProxyException(COMException comException)
            à System.Transactions.TransactionInterop.GetOletxTransactionFromTransmitterPropigationToken(Byte[] propagationToken)
            à System.Transactions.TransactionStatePSPEOperation.PSPEPromote(InternalTransaction tx)
            à System.Transactions.TransactionStateDelegatedBase.EnterState(InternalTransaction tx)
            à System.Transactions.EnlistableStates.Promote(InternalTransaction tx)
            à System.Transactions.Transaction.Promote()
            à System.Transactions.TransactionInterop.ConvertToOletxTransaction(Transaction transaction)
            à System.Transactions.TransactionInterop.GetExportCookie(Transaction transaction, Byte[] whereabouts)
            à System.Data.SqlClient.SqlInternalConnection.GetTransactionCookie(Transaction transaction, Byte[] whereAbouts)
            à System.Data.SqlClient.SqlInternalConnection.EnlistNonNull(Transaction tx)
            à System.Data.SqlClient.SqlInternalConnection.Enlist(Transaction tx)
            à System.Data.SqlClient.SqlInternalConnectionTds.Activate(Transaction transaction)
            à System.Data.ProviderBase.DbConnectionInternal.ActivateConnection(Transaction transaction)
            à System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject)
            à System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
            à System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
            à System.Data.SqlClient.SqlConnection.Open()
            à System.Data.EntityClient.EntityConnection.OpenStoreConnectionIf(Boolean openCondition, DbConnection storeConnectionToOpen, DbConnection originalConnection, String exceptionCode, String attemptedOperation, Boolean& closeStoreConnectionOnFailure)
       InnerException: System.Runtime.InteropServices.COMException
            Message="Le gestionnaire de transactions a désactivé sa prise en charge de transactions à distance/réseau. (Exception de HRESULT : 0x8004D024)"
            Source="System.Transactions"
            ErrorCode=-2147168220
            StackTrace:
                 à System.Transactions.Oletx.IDtcProxyShimFactory.ReceiveTransaction(UInt32 propgationTokenSize, Byte[] propgationToken, IntPtr managedIdentifier, Guid& transactionIdentifier, OletxTransactionIsolationLevel& isolationLevel, ITransactionShim& transactionShim)
                 à System.Transactions.TransactionInterop.GetOletxTransactionFromTransmitterPropigationToken(Byte[] propagationToken)
            InnerException:
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now