Solved

Use Isolation level in LINQ

Posted on 2009-05-05
2
3,416 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

773 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