Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Use Isolation level in LINQ

Posted on 2009-05-05
2
Medium Priority
?
3,540 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 43

Expert Comment

by:Eugene Z
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…

782 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