O/H Mike Kershaw έγραψε: > > > Hi Mauro, > > Yes you can run nested transactions, it is possible under SQL Server, I > should have asked actually which database you were using for the back end? > > You can also set save points and rollback points within your > transactions so if part of it fails then you can roll back to different > parts of the transaction depending on what you need. > > With the exception I believe your issue is arising because the for loop > is within the BeginTrans call, a single rollback will always roll back > entire transaction. > > "But, still a question: is really not possible to switch the behavior > "exception => transaction closure" to the behavior "exception !=> > transaction closure"?" > Do you mean by this you only want the Transaction to roll back under > certain exceptions? Sorry did quite get that bit. > > Mike.
mauro as Mike pointed out, many things depend on the kind of database you use. For example, if you want to be sure that your database supports transactions at all then you have to code something like the following uses ADODB ,OLEDB ; if MyConnection.Connected then try FSupportsTransactions := MyConnection.Properties['Transaction DDL'].Value > DBPROPVAL_TC_NONE; except FSupportsTransactions := False; end; ADO is a midware and Delphi's ADO component set is a wrapper around that technology. http://msdn.microsoft.com/en-us/library/ms675532(VS.85).aspx ADO could be used to access anything that is accessible through an OLE DB Provider, that is a driver. That anything could be an SQL server database such as Oracle, MS SQL or Firebird or even an MS Access database, an MS Excel file, a text file and do on. So you have to query your driver, that Provider, for its capabilities. As for nested transactions through ADO and Delphi's ADO components... Avoid nested transactions if possible. ADO supports nested transactions but I think, not sure though and please correct me here if I'm wrong, there is a limit as to how many nesting levels are acceptable. I think is 6 or something. In any case (ADO or not), one should carefully configure transaction properties and that's especially true when it comes to nested transactions, in order to avoid deadlocks. Code taken from your message MyAdoConnection.BeginTrans(); try Insert in a MyTable1 for each row on a MyTable2 do Insert in a MyTable3 through a) preparing MyADOQuery b) executing MyADOQuery by try MyADOQuery.ExecSQL(); except // this is going to hide any failure end; MyAdoConnection.CommitTrans(); except MyAdoConnection.RollbackTrans(); end; The nested try..except is a bad practice try MyADOQuery.ExecSQL(); except // this is going to hide any failure end; Let any failure-exception to reach the outer except..end. Otherwise your code will reach MyAdoConnection.CommitTrans() even when the MyADOQuery.ExecSQL(); fails. Theo -- Regards Theo ------------------------ Theo Bebekis Thessaloniki, Greece ------------------------ The resource you are looking for has been removed, had its name changed, or is temporarily unavailable. ------------------------ Greek_Delphi_Prog : a Delphi Programming mailing list in Greek at http://groups.yahoo.com/group/Greek_Delphi_Prog CSharpDotNetGreek : A C# and .Net mailing list in Greek language at http://groups.yahoo.com/group/CSharpDotNetGreek atla_custom : a Unisoft Atlantis Customization mailing list at http://groups.yahoo.com/group/atla_custom ------------------------ ------------------------------------ ----------------------------------------------------- Home page: http://groups.yahoo.com/group/delphi-en/ To unsubscribe: delphi-en-unsubscr...@yahoogroups.comyahoo! Groups Links <*> To visit your group on the web, go to: http://groups.yahoo.com/group/delphi-en/ <*> Your email settings: Individual Email | Traditional <*> To change settings online go to: http://groups.yahoo.com/group/delphi-en/join (Yahoo! ID required) <*> To change settings via email: mailto:delphi-en-dig...@yahoogroups.com mailto:delphi-en-fullfeatu...@yahoogroups.com <*> To unsubscribe from this group, send an email to: delphi-en-unsubscr...@yahoogroups.com <*> Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/