Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Problem using scope with linq

Posted on 2009-05-05
11
Medium Priority
?
2,057 Views
Last Modified: 2013-11-11
I must specify the isolation level  for some transaction, so I've tried something like in the code snippet.

But we always have an exception.

I'm sorry, I've VS in french and all exception message are in french too :(

Information about the exception:

   à 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 168
   à QueryHelper.insertDB(InsertDbDelegate methodThatWriteDB, IsolationLevel isoLevel, Page senderPage) dans xxxxx\QueryHelper.cs:ligne 47


ex = {"Échec du fournisseur sous-jacent sur Open."}
//If I translate this, it would be something like : "Failure of the underlying provider on Open."

InnerException = {"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."}
//Translation
Access network MSDTC (Distributed Transaction Manager) has been disabled. Activate DTC for network access in the security configuration for MSDTC using the Services administrative tool components.


I've a MS SQL 2005 standard Database and I currently only use the "debug" and "local" server of visual studio.

So what can I make?

Is there a better way to manage isolation level for a transaction?


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();
                    addUserMessage(senderPage, "Insertion OK");
                } 
            }
        }
        catch (Exception ex)
        {
            addErrorMessage(senderPage, "Error message");
        }

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
  • 6
  • 5
11 Comments
 
LVL 15

Expert Comment

by:mohan_sekar
ID: 24305354
Is the database service running on a different server? If so, have you enabled MS DTC on that server?
0
 
LVL 1

Author Comment

by:Nargzul
ID: 24305361
Yes he is running on a different server, and we've activated this server, but I don't know if I've done all these manipulation correctly
0
 
LVL 15

Expert Comment

by:mohan_sekar
ID: 24305472
You shall try configuring your DTC as per the attached screenshot
DTC.GIF
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:Nargzul
ID: 24305523
We've already the same thing :(
0
 
LVL 15

Expert Comment

by:mohan_sekar
ID: 24305571
on both the machines?
0
 
LVL 1

Author Comment

by:Nargzul
ID: 24305611
both? Which other than the sql server?

We just have a visual studio to test currently
0
 
LVL 15

Expert Comment

by:mohan_sekar
ID: 24305684
Are you trying to open more than one database connection? If so, try closing the 1st connection before opening a new connection?
0
 
LVL 1

Author Comment

by:Nargzul
ID: 24305693
No, we just have one database.(and our developper are under vista(sigh))
0
 
LVL 15

Expert Comment

by:mohan_sekar
ID: 24305772
you didn't understand my point - I asked whether you are opening more than one database connection in your application/program...phew
0
 
LVL 1

Author Comment

by:Nargzul
ID: 24306461
I've added explicit "dispose()" to the object context, but nothing change.
0
 
LVL 1

Accepted Solution

by:
Nargzul earned 0 total points
ID: 24361745
The problem was in the MSDTC configuration of the local computer
0

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

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

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…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

618 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