c# .NET und die Transaktionen
semteX 12.03.2010 - 10:13 2182 4
semteX
hasst die KI
|
grüße
ich habe im prinzip folgendes Problem:
Ich hab über ganze Methoden ein using (TransactionScope scope = new TransactionScope()) { } drübergestülpt. so weit so einfach.
jetzt hab ich aber in einer konkreten methode das problem, dass ich in dieser eine "eigene" transaktion brauch. wenn ich diese mit
DbDataContext dbc = new DbDataContext (kommt vom linq 2 sql) dbc.Transaction = null; dbc.Connection.BeginTransaction() aufmach enlistet er automatisch in die globale Transaktion vom using. das ist unterm strich "gscheit *****" weil es durch starke asynchronitäten dazu kommen kann, dass die gobale transaktion vom using schon lang weg ist, wenn ich die "innere" noch brauchn würde... Was ich also suchen würde ist: wie sag ich ihm, dass er einfach nur eine deppate lokale transaktion verwenden soll UND SONST NIX?
also keinen scope (ich kann den scope ned aufziehen weil ich ned weiß wie lang der gelten muss), ...
ich würd eigentlich nur ne methode SqlConnection.CreateNewLocalTransaction, die einfach nur a kleine transaktion aufmacht, welche von allem andern komplettest entkoppelt ist...
danke!
|
DirtyHarry
aka robobimbo
|
hast du schon versucht dir einfach zwei transaction scopes zu holen? ich weiss nicht ob du da aber deinen speziellen fall da geregelt bekommst, ich glaub nämlich fast die sind dann auch nested, bzw. hab ich noch nie was in der richtung probiert. Beisiel für eine nested Ausführung, aber das brauchst Du ja nicht wenn ich es richtig verstanden hab. class Foo : List<Bar>{
public void Commit() {
using (TransactionScope tran = new TransactionScope()) {
foreach (Bar b in this) {
b.Commit();
}
tran.Complete();
}
}
}
class Bar {
public void Commit() {
using (TransactionScope tran = new TransactionScope()) {
......
tran.Complete();
}
}
}
Gerade in der MSDN gelesen, es gibt für den TransactioScope eine Überladung bei der man einen neuen root scope Erzeugen kann, dass sollte dann für dich das richtige sein: http://msdn.microsoft.com/en-us/library/ms172152.aspx using(TransactionScope scopeBar = new TransactionScope(TransactionScopeOption.RequiresNew))
{
...
}
|
semteX
hasst die KI
|
woa, sorry, den thread hatte ich leider vor lauter anderen projekten vergessen :/
das blöde an transactionscopes ist, dass die methoden, in denen diese transaktion verwendet wird, extremst oft aber immer nur sehr kurz aufgerufen werden. wenn ich jetzt die Read Methode z.b. mit nem Scope überdecke will ich ned wissn was passiert, wenn innerhalb von 10 sekunden 100k transaktionen geöffnet und geschlossen werden müssen... darum hätt ich auch gern ne transaktion gehabt welche geöffnet wird, dann 100k methodenaufrufe, dann commit und "passt"...
|
DirtyHarry
aka robobimbo
|
Dann schau Dir mal das mit den expliziten Transaktionen an - http://msdn.microsoft.com/en-us/library/ms172146.aspxThe CommittableTransaction class provides an explicit way for applications to use a transaction, as opposed to using the TransactionScope class implicitly. It is useful for applications that want to use the same transaction across multiple function calls or multiple thread calls. Unlike the TransactionScope class, the application writer needs to specifically call the Commit and Rollback methods in order to commit or abort the transaction.
|
semteX
hasst die KI
|
ja, den weg hab ich jetzt eh gewählt... find ich halt nur mittelgeil weils das unterliegende problem ned löst...
danke
|