2008-11-26 21 views
5

Estoy tratando de configurar una transacción simple para mis acciones Linq-to-Sql en mi base de datos Sql 2000. Usando TransactionScope se ve así:Error de TransactionScope contra Sql Server 2000 - El administrador de transacciones asociado ha deshabilitado su soporte para transacciones remotas/de red

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; 
    } 
} 

Sin embargo, me siguen dando el siguiente error: administrador de transacciones

El socio ha deshabilitado su soporte para las transacciones a distancia/red. (Excepción de HRESULT: 0x8004D025)

Pero, si configuro la transacción con una transacción tradicional, funciona bien. Por lo que este funciona bien:

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; 
} 

Me pregunto si el TransactionScope está haciendo algo diferente bajo las sábanas de mi segunda aplicación. Si no, ¿qué estoy perdiendo al no usar TransactionScope? Además, cualquier orientación sobre qué está causando el error sería bueno también. Confirmé que MSDTC se está ejecutando en el servidor sql y en mi máquina cliente.

Respuesta

6

Tome un vistazo aquí:

Transacciones rápidas con System.Transactions y Microsoft SQL Server 2000 http://blogs.msdn.com/florinlazar/archive/2005/09/29/475546.aspx

Y aquí:
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.

+0

La DatabaseTransactionAdapter hace referencia en el post Florin Lazar hizo el truco. Publicaré mi código de implementación como respuesta. –

+0

Las instrucciones para configurar el MSDTC no parecen aplicarse a Windows 7 Solo tengo una opción en la pestaña MSDTC que dice: use el coordinador local o especifique el host remoto para usar. – Myster

+1

¡Encontré instrucciones para encontrar estas configuraciones en Windows 7 y 2008! Mire aquí: http://msdn.microsoft.com/en-us/library/aa561924(BTS.20).aspx – skb

2

La aplicación DatabaseTransactionAdapter en el Florin Lazar mensaje que Keith Sirmons me indicó que parece hacer el truco. Aquí está mi código que llama:

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; 
    } 
} 

La única cosa que me inquieta es que yo no voy a cerrar explícitamente la conexión incluso aunque no se declara dentro de una declaración 'utilizar'.

Pero según Florin Lazar, eso es a propósito.

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.

0

más cuenta de que: - Guía de configuración del servidor Habilitar red COM + acceso (Windows Server 2003) Inicio ==> Panel de control ==> Agregar o quitar programas ==> Agregar/quitar componentes de Windows, seleccione Servidor de aplicaciones, y luego haga clic en Detalles. Haga clic en Habilitar acceso COM + de red y luego en Aceptar. Haga clic en Siguiente y luego en Finalizar.
- Si entre 2 servidores tiene cortafuegos, abra el cortafuegos para entrada/salida en este puerto de rango: Haga clic en Inicio ==> Paneles de control ==> Herramientas administrativas ==> Servicios de componentes. Expanda el servicio de componentes, expanda computadoras, haga clic con el botón derecho en Mi PC y elija Propiedades. En la ventana Propiedades de Mi PC, haga clic en la pestaña Protocolo predeterminado, haga clic en TCP/IP orientado a conexión y elija propiedades. en la nueva ventana, haga clic en Agregar y escriba el nuevo rango de puertos DTC. Haga clic en Aceptar para aplicar estos cambios. Server debe ser de reinicio para el nuevo cambio surta efecto

1

Los pasos para habilitar esto en Windows 2008 o posterior son:

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.

Cuestiones relacionadas