Moin Leute,
in eine Funktion, welche bestimmte Firebird-Datenbank-Inserts macht, wollte ich nun ein TransactionScope implementieren, um alle Inserts evtl. wieder rückgängig machen zu können. Die Funktion hat im wesentlichen folgenden Aufbau:
C#-Quelltext
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28:
| private void DoSomething() { new Thread((ThreadStart)delegate { using (var transactionScope = new System.Transactions.TransactionScope()) { while () { try { Invoke((MethodInvoker)delegate { RefreshDisplayControls(); }); } catch (Exception) { break; } }
if () transactionScope.Complete(); } }).Start(); } |
Meiner Erwartung nach dürften die Inserts nur commited werden, wenn
transactionScope.Complete() aufgerufen wird. Tatsächlich werden die Datensätze aber immer angelegt.
Getestet habe ich auch schon:
- für alle Inserts nur eine offene Connection benutzen (aktuell mache ich immer eine neue)
- das ganze nicht in einem neuen Thread laufen zu lassen
==> brachte das selbe Ergebnis
Hat jemand den rettenden Tipp für mich oder erkennt den Fehler bei der Umsetzung?
Danke im voraus
Julian
Moderiert von Christian S.: Topic aus Basistechnologien verschoben am Mi 05.12.2018 um 15:22