Results 1 to 4 of 4

Thread: when do we use 'sqltransaction' class?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2003
    Posts
    436

    when do we use 'sqltransaction' class?

    I am aware that we can put bunch of database transactions like 'insert'/'update/delete between begin and commit and in the catch block depending on the seriousness of the error that occured we can rollback.

    Is that the right scenario to use sqltransaction class?

    Is there any equivalent class for oracle database?

    thanks
    nath

  2. #2
    Addicted Member
    Join Date
    Aug 2003
    Posts
    153
    I use sql transactions whenever I am preforming any sort of update on a database which affects more than 1 record, mainly due to system integrity, don't want half the additions/updates going thru, while the other half don't. All or nothing.

  3. #3
    Hyperactive Member
    Join Date
    Mar 2002
    Location
    Dublin (Ireland)
    Posts
    304
    Perhaps I shoukld start this as a new thread,but I found for that I had to have a separate connection for each begintranasaction amd never figured out why.

  4. #4
    Addicted Member
    Join Date
    Aug 2003
    Posts
    153
    Because an sql transaction is tied to a connection. You should only use being transaction when you want to begin a set of transactions based on a connection. eg

    VB Code:
    1. 'Start the transaction
    2. myTransaction = myConnection.BeginTransaction
    3.  
    4. 'Set the commands to the transaction
    5.  
    6. cmdOne.Transaction = myTransaction
    7. cmdTwo.Transaction = myTransaction
    8. cmdThree.Transaction = myTransaction
    9.  
    10. 'Begin executing all the commands
    11. Try
    12.   cmdOne.ExecuteNonQuery
    13.   cmdTwo.ExecuteNonQuery
    14.   cmdThree.ExecuteNonQuery
    15.   myTransaction.Commit
    16. Catch ex As exception
    17.   myTransaction.Rollback
    18. End Try

    In the above example this one connection with one transaction for multiple sql commands. The transaction begins at begin transaction, and finishes when either commit or rollback is used.

    Doing it so that it's a one to one relationship between a transaction, command, and connection defeats the purpose of sql connections.
    Last edited by Carnifex; Dec 30th, 2003 at 09:32 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width