locked
transaction option Vs Ado.Net Transaction RRS feed

  • Question

  • can we use transaction option and ADO.Net transaction in the same serviced component? like for example can this work

    <transaction(transactionop.requiresnew)> _ ---SERVICED COMPONENT's OWN TRANSACTION

    Public Class ABC

    public function XYZ() as boolean

    trans=connection.begintransaction  --- ADO.NET TRANSACTION

    try

    command.trancation=trans

     

    trans.commit

    catch

    trans.rollback

    end try

    End Class

    i think if i dont use Centextutil.SetAbort or ContextUtil.SetComplete or define my transactionscope as <AutoComplete()> function XYZ will not behave properly..  the two transactions of ADO.net and TransactionScope will overlap and the net result will be an error or some data loss..????

    am i rite???

     

    Any detailed guidance will be very much helpful here...

    • Edited by NET HAWK Thursday, June 10, 2010 5:19 AM Wrong Entry
    • Moved by John Saunders Thursday, June 10, 2010 8:05 AM transaction q (From:ASMX Web Services and XML Serialization)
    Thursday, June 10, 2010 5:18 AM

Answers

  • You dont need to go for both.  there is different need for going MSDTC. Suppose you have multiple database servers where in one server you are updating some records and in other one you want to insert some records and you want to manage it in a transaction.

     

    So when you use ado.net transaction it will work with single connection so different connection act as different transaction but when you go to MSDTC it will manage it as a single transaction.

    Thursday, July 15, 2010 6:25 AM

All replies

  • Hello

    Did you consider flowing the ambient transaction thats already present throughTransactionScope to SQL? Do you have specific reasons to create a different ADON.net transaction?

    Thanks.

    Tuesday, June 22, 2010 11:23 PM
    Moderator
  • i simply want to create an isolated transaction, where when one user is interacting with the record, the other user may not alter it,

    consider the scenario as an environment where customer balance can be updated by more than one users, so the balances may be up-to-date all the time in order to prevent any wrong Debit/Credit into the balances.

    there is a single database, and there can be more than one databases depending upon the circumstances of the transactions. but we are at the moment working on single database instance, that is, the transaction hits only single SQL Server database.Also inserting a single entry requires entry into more than one tables, and after all the tables are successfully updated the transaction is considered as complete, otherwise rollback is required for all the tables.

    so what is the preferred approach for doing this? some lines of code will be very much useful along with the use of each line.

    the database can be remote or local. both cases need to be dealt.

     

    Any Help Please!

    Thursday, June 24, 2010 4:17 AM
  • No idea about ambient transactions and passing scopes to ambient transactions. please guide.

     

    Thursday, June 24, 2010 4:23 AM
  • Ambient transaction is the transaction that the client is flowing to the service and you can do the database access in the same transaction. If you connect to the database being part of the transaction thats flown from the client or the one you are already enslisted in then you dont need to enlist your SQL connection in a separate transaction. This article talks about manual transactions connecting to a Db

    http://msdn.microsoft.com/en-us/library/ms978457.aspx

    Thanks.

    • Proposed as answer by edhickey Friday, July 23, 2010 7:31 PM
    Friday, June 25, 2010 5:40 PM
    Moderator
  • You dont need to go for both.  there is different need for going MSDTC. Suppose you have multiple database servers where in one server you are updating some records and in other one you want to insert some records and you want to manage it in a transaction.

     

    So when you use ado.net transaction it will work with single connection so different connection act as different transaction but when you go to MSDTC it will manage it as a single transaction.

    Thursday, July 15, 2010 6:25 AM