Victor Rodrigues
Victor Rodrigues

Reputation: 11713

Why is TransactionScope causing problems using Entity Framework?

I have a problem that I know is something local, related to transaction scope, probably MSDTC (I don't know very much about it).

The other project developer (same codebase, everything commited) executes the whole solution, but when I try to get some data from the database (not always), I have the following error:

The underlying provider failed on EnlistTransaction.


   at System.Data.EntityClient.EntityConnection.EnlistTransaction(Transaction transaction)
   at System.Data.Objects.ObjectContext.EnsureConnection()
   at System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)
   at System.Data.Objects.ObjectQuery`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator()
   at System.Linq.Enumerable.First[TSource](IEnumerable`1 source)
   at System.Data.Objects.ELinq.ObjectQueryProvider.<GetElementFunction>b__0[TResult](IEnumerable`1 sequence)
   at System.Data.Objects.ELinq.ObjectQueryProvider.ExecuteSingle[TResult](IEnumerable`1 query, Expression queryRoot)
   at System.Data.Objects.ELinq.ObjectQueryProvider.System.Linq.IQueryProvider.Execute[S](Expression expression)
   at System.Linq.Queryable.First[TSource](IQueryable`1 source, Expression`1 predicate)

If I comment the using transaction scope, complete() and everything, it works as expected.

Have you ever had this problem before?

EDIT:

The query that throws this error is something very simple, like:

var entity = Entities.EntityX.First(p => p.ID == id);

EDIT, SOLVED:

Server's lmhosts was outdated.

Upvotes: 1

Views: 2678

Answers (1)

tvanfosson
tvanfosson

Reputation: 532445

Firewall rules blocking the DTC ports, maybe? Or an incomplete firewall rule allowing some DTC ports, but not others? I've never gotten distributed transactions to work well through a firewall. Even after following the directions.

Upvotes: 2

Related Questions