Solved

Use Isolation level in LINQ

Posted on 2009-05-05
2
3,454 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

710 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