TransactionScope weirdness timeout with TransactionScopeOption.RequiresNew

Something supernatural is happening here.

I just added a transaction area around some legacy code that I was debugging to ensure that the driving I was doing was not fixed.

This worked twice, then said:

"The transaction manager has disabled its support for remote/network transactions."

without any code changes or changes between working / inoperative (literally 3 F5 per line [web application]). This was local code connecting the remote database server.

Since this is completely separate code in another project, this is the time. If I remove the Scopes transactions from this code, it works fine, but it’s time with them in place. I tried my local SQL server and remote, both timeouts inside a Scope transaction.

What the hell is going on?

Edit: I found that I changed TransactionScopes to:

using (var scope = new TransactionScope(TransactionScopeOption.RequiresNew))

to

using (var scope = new TransactionScope())

prevents the problem: s

What does it mean?

+3
source share
3 answers

Difference between:

using (var scope = new TransactionScope(TransactionScopeOption.RequiresNew))

and

using (var scope = new TransactionScope())

Is the second a reuse of an existing (external) transaction, while the first creates a new transaction in the old.

For this transaction, the transaction requires a Distributed Transaction Coordinator.

There are three possible reasons for your error:

  • MSDTC does not work
  • Your database is located on another computer, and the windows are configured to not allow transactions from the network.
  • Your database is located on a different computer, and the SQL server is configured to not allow transactions from the network.
+3
source

, , , , "" (.. ) "" . MSDTC (Distributed Transaction Transaction Coordinator), , , .

, ( ) . , (-) . , , .

0

, , .

TransactionScopeOption.RequiresNew TransactionScopeOption.Required , , MSDN. , , "".

, :

using (var scope = new TransactionScope(TransactionScopeOption.RequiresNew))

:

  • IsolationLevel Serializable ( IsolationLevel.ReadCommitted)
  • TimeOut ( TransactionManager.MaximumTimeout)

TransactionScopeOption.RequiresNew .

:

new TransactionScope(TransactionScopeOption.Required, 
    new TransactionOptions 
    {
        IsolationLevel = IsolationLevel.ReadCommitted,
        Timeout = TransactionManager.MaximumTimeout
    }
)
0
source

Source: https://habr.com/ru/post/1707178/


All Articles