Link to home
Start Free TrialLog in
Avatar of Nargzul
Nargzul

asked on

Use Isolation level in LINQ

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

Avatar of EugeneZ
EugeneZ
Flag of United States of America image

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
ASKER CERTIFIED SOLUTION
Avatar of Nargzul
Nargzul

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial