2008-11-26 7 views
5

Ich versuche einzurichten, eine einfache Transaktion deaktiviert. Mit Transaction sieht es wie folgt aus:Transaction Fehler gegen SQL Server 2000 - Der Partner Transaktions-Manager hat für meine Linq-to-Sql Aktionen gegen meine SQL 2000 Datenbank seine Unterstützung für Remote/Netzwerk-Transaktionen

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

Allerdings halte ich die folgende Fehlermeldung erhalten:

Der Partner Transaktionsmanager seine Unterstützung für Remote/Netzwerk-Transaktionen deaktiviert hat. (Ausnahme von HRESULT: 0x8004D025)

Aber wenn ich die Transaktion mit einer herkömmlichen Transaktion einrichten, funktioniert es einwandfrei. Also das funktioniert gut:

Ich frage mich, ob das TransactionScope etwas anderes unter den Abdeckungen als meine zweite Implementierung tut. Wenn nicht, was verliere ich, wenn ich TransactionScope nicht verwende? Außerdem wäre jede Anleitung zu dem, was den Fehler verursacht, auch gut. Ich habe bestätigt, dass MSDTC sowohl auf SQL Server als auch auf meinem Clientcomputer ausgeführt wird.

Antwort

6

einen Blick hier nehmen:

Schnelle Transaktionen mit System.Transactions und Microsoft SQL Server 2000 http://blogs.msdn.com/florinlazar/archive/2005/09/29/475546.aspx

Und hier:
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

Die DatabaseTransactionAdapter in der Post Florin Lazar referenzierten den Trick. Ich werde meinen Implementierungscode als Antwort veröffentlichen. –

+0

Die Anweisungen zum Konfigurieren des MSDTC scheinen nicht für Windows 7 zu gelten. Ich habe nur eine Option unter der Registerkarte MSDTC, die besagt: Verwenden Sie den lokalen Koordinator oder den zu verwendenden Remote-Host. – Myster

+1

Ich habe Anweisungen gefunden, um diese Einstellungen unter Windows 7 und 2008 zu finden! Schau hier: http://msdn.microsoft.com/en-us/library/aa561924(BTS.20).aspx – skb

2

Die DatabaseTransactionAdapter Umsetzung im Florin Lazar Post, auf den Keith Sirmons mich hingewiesen hat, scheint den Trick zu machen. Hier ist mein Code, der es nennt:

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

Das einzige, was mich unruhig macht, ist, dass ich nicht explizit die Verbindung geschlossen wird, auch wenn es nicht innerhalb einer ‚mit‘ Anweisung deklariert wird.

Aber nach Florin Lazar, das ist absichtlich.

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

mehr feststellen, dass: - Server Configuration Guide Aktivieren COM + -Netzwerkzugriff (Windows Server 2003) starten ==> Systemsteuerung ==> Software entfernen ==> Hinzufügen/Entfernen von Windows-Komponenten, Wählen Anwendungsserver, und klicken Sie dann auf Details. Klicken Sie auf Netzwerk COM + -Zugriff aktivieren, und klicken Sie dann auf OK. Klicken Sie auf Weiter und dann auf Fertig stellen.
- Wenn zwischen zwei Server-Firewall, offener Firewall für beide in/out in diesem Bereich Hafen: Klicken Sie auf Start ==> Systemsteuerung ==> Verwaltung ==> Komponentendienste. Erweitern Sie Komponentendienst, erweitern Sie Computer, klicken Sie mit der rechten Maustaste auf Arbeitsplatz, und wählen Sie Eigenschaften. Klicken Sie im Fenster "Arbeitsplatzeigenschaften" auf die Registerkarte Standardprotokoll, klicken Sie auf verbindungsorientiertes TCP/IP und wählen Sie Eigenschaften. Klicken Sie im neuen Fenster auf Hinzufügen und geben Sie den neuen DTC-Port-Bereich ein. Klicken Sie auf OK, um diese Änderungen zu übernehmen. Server muss Neustart für neuen Änderungseffekt

1

Die Schritte unternimmt, um diese auf Windows 2008 zu aktivieren oder später ist:

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.