TransactionScope Error against Sql Server 2000 - The partner transaction manager has disabled its support for remote/network transactions
Asked Answered
S

5

5

I am trying to set up a simple transaction for my Linq-to-Sql actions against my Sql 2000 database. Using TransactionScope it looks like this:

using (TransactionScope transaction = new TransactionScope())
{
    try
        {
        Store.DBDataContext dc = new Store.DBDataContext();
        Store.Product product = GetProduct("foo");
        dc.InsertOnSubmit(product);
        dc.SubmitChanges();
        transaction.Complete();
    }
    catch (Exception ex)
    {                
        throw ex;
    }
}

However, i keep getting the following error:

The partner transaction manager has disabled its support for remote/network transactions. (Exception from HRESULT: 0x8004D025)

But, if I set up the transaction using a traditional transaction, it works fine. So this works fine:

Store.DBDataContext dc = new Store.DBDataContext();
try
{
    dc.Connection.Open();
    dc.Transaction = dc.Connection.BeginTransaction();
    Store.Product product = GetProduct("foo");
    dc.InsertOnSubmit(product);
    dc.SubmitChanges(); 
    dc.Transaction.Commit();
}
catch (Exception ex)
{
    dc.Transaction.Rollback();
    throw ex;
}
finally
{
    dc.Connection.Close();      
    dc.Transaction = null;
}

I'm wondering if the TransactionScope is doing something different under the covers than my second implementation. If not, what am I losing by not using TransactionScope? Also, any guidance on what is causing the error would be good too. I've confirmed that MSDTC is running in both sql server and on my client machine.

Seagrave answered 26/11, 2008 at 15:0 Comment(0)
L
6

Take a look here:

Fast transactions with System.Transactions and Microsoft SQL Server 2000 http://blogs.msdn.com/florinlazar/archive/2005/09/29/475546.aspx

And here:
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=230390&SiteID=1

First verify the "Distribute Transaction Coordinator" Service is running on both database server computer and client computers
1. Go to "Administrative Tools > Services"
2. Turn on the "Distribute Transaction Coordinator" Service if it is not running

If it is running and client application is not on the same computer as the database server, on the computer running database server
1. Go to "Administrative Tools > Component Services"
2. On the left navigation tree, go to "Component Services > Computers > My Computer" (you may need to double click and wait as some nodes need time to expand)
3. Right click on "My Computer", select "Properties"
4. Select "MSDTC" tab
5. Click "Security Configuration"
6. Make sure you check "Network DTC Access", "Allow Remote Client", "Allow Inbound/Outbound", "Enable TIP" (Some option may not be necessary, have a try to get your configuration)
7. The service will restart
8. BUT YOU MAY NEED TO REBOOT YOUR SERVER IF IT STILL DOESN'T WORK (This is the thing drove me crazy before)

On your client computer use the same above procedure to open the "Security Configuration" setting, make sure you check "Network DTC Access", "Allow Inbound/Outbound" option, restart service and computer if necessary.

On you SQL server service manager, click "Service" dropdown, select "Distribute Transaction Coordinator", it should be also running on your server computer.

Letdown answered 26/11, 2008 at 15:24 Comment(3)
The DatabaseTransactionAdapter referenced in the Florin Lazar post did the trick. I'll post my implementation code as a response.Seagrave
The instructions for configuring the MSDTC don't seem to apply to windows 7 I only have one option under the MSDTC tab it says: use local coordinator or specify remote host to use.Redolent
I found instructions for finding these settings on Windows 7 and 2008! Look here: msdn.microsoft.com/en-us/library/aa561924(BTS.20).aspxTriphylite
S
3

The DatabaseTransactionAdapter implementation in the Florin Lazar post that Keith Sirmons pointed me to seems to do the trick. Here's my code that calls it:

Store.DBDataContext dc = new Store.DBDataContext();
using (TransactionScope transaction = new TransactionScope())
{
    try
    {
        var dbAdapter = new DatabaseTransactionAdapter(dc.Connection);
        dc.Connection.Open();
        dbAdapter.Begin();
        dc.Transaction = (SqlTransaction)dbAdapter.Transaction;
        Store.Product product = GetProduct("foo");
        dc.InsertOnSubmit(product);
        dc.SubmitChanges();
        transaction.Complete();
    }
    catch (Exception ex)
    {                
        throw ex;
    }
}

The only thing that makes me uneasy is that I'm not explicitly closing the connection even though it's not declared within a 'using' statement.

But according to Florin Lazar, that's on purpose.

And you also must not close the connection, because the connection should stay open until the transaction is completed, which happens after the “using” statement ends. The adapter will take ownership of the connection lifetime and close it when it is done with it.

Seagrave answered 26/11, 2008 at 15:52 Comment(0)
S
1

The steps to enable this on Windows 2008 or later are:

First verify the "Distribute Transaction Coordinator" Service is running on both database server computer and client computers

  1. Go to "Administrative Tools > Services"
  2. Turn on the "Distribute Transaction Coordinator" Service if it is not running

If it is running and client application is not on the same computer as the database server, on the computer running database server

  1. Go to "Administrative Tools > Component Services"
  2. On the left navigation tree, go to "Component Services > Computers > My Computer > Distributed Transaction Coordinator" (you may need to double click and wait as some nodes need time to expand)
  3. Right click on "Local DTC", select "Properties"
  4. Select "Security" tab
  5. Make sure you check "Network DTC Access", "Allow Remote Client", "Allow Inbound/Outbound"
  6. The service will restart
  7. BUT YOU MAY NEED TO REBOOT YOUR SERVER IF IT STILL DOESN'T WORK (This is the thing drove me crazy before)

On your client computer use the same above procedure to open the "Security Configuration" setting, make sure you check "Network DTC Access", "Allow Inbound/Outbound" option, restart service and computer if necessary.

On your SQL server service manager, click "Service" dropdown, select "Distribute Transaction Coordinator", it should be also running on your server computer.

Sari answered 26/7, 2013 at 17:39 Comment(0)
A
1

I post the below solution here because after some searching this is where I landed, so other may too. I was trying to use EF 6 to call a stored procedure, but had a similar error because the stored procedure had a linked server being utilized.

The operation could not be performed because OLE DB provider _ for linked server _ was unable to begin a distributed transaction

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

Jumping over to SQL Client did fix my issue, which also confirmed for me that it was an EF thing.

EF model generated method based attempt:

db.SomeStoredProcedure();

ExecuteSqlCommand based attempt:

db.Database.ExecuteSqlCommand("exec [SomeDB].[dbo].[SomeStoredProcedure]");

With:

var connectionString = db.Database.Connection.ConnectionString;
var connection = new System.Data.SqlClient.SqlConnection(connectionString);    
var cmd = connection.CreateCommand();
cmd.CommandText = "exec [SomeDB].[dbo].[SomeStoredProcedure]";

connection.Open();
var result = cmd.ExecuteNonQuery();

That code can be shortened, but I think that version is slightly more convenient for debugging and stepping through.

I don't believe that Sql Client is necessarily a preferred choice, but I felt this was at least worth sharing if anyone else having similar problems gets landed here by google.

Aquiline answered 10/5, 2018 at 16:47 Comment(0)
L
0

more notice that: - Server Configuration Guide Enable network COM+ access (Windows Server 2003) Start ==> Control Panel ==> Add or Remove Programs ==>Add/Remove Windows Components, Select Application Server, and then click Details. Click Enable network COM+ access, and then click OK. Click Next, and then click Finish.
- If between 2 server have firewall, open firewall for both in/out on this range port: Click Start ==> Control Panels ==> Administrative Tools ==> Component Services. Expand Component service, expand Computers, Right click on My Computer and choose Properties. In the My Computer Properties window, click on tab Default Protocol, click on connection-oriented TCP/IP and choose properties. in the new window, click add and type new DTC ports range. Click on OK to apply these change. Server must be restart for new change take effect

Litho answered 26/3, 2009 at 7:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.