Results 1 to 3 of 3

Thread: ADO Transactions

  1. #1

    Thread Starter
    Fanatic Member carlblanchard's Avatar
    Join Date
    Sep 2003
    Location
    Bournemouth (UK)
    Posts
    539

    Unhappy ADO Transactions

    Hey all i got a small problem (IM DUMB) no thats not the problem,

    I am trying to do a ado transaction with more than 2 stored procs

    this is my current code (snippet)
    ---------------------------------------------------------------------------
    Dim myCommand As New SqlCommand("insTrustedUsers", myConnection)

    myConnection.Open()

    ' Start a local transaction.
    Dim myTrans As SqlTransaction = myConnection.BeginTransaction()

    ' Enlist the command in the current transaction.
    'Dim myCommand As SqlCommand = myConnection.CreateCommand()
    myCommand.Transaction = myTrans

    Try
    myCommand.CommandType = CommandType.StoredProcedure
    myCommand.Parameters.Add("@firstname", "Carl")
    myCommand.Parameters.Add("@surname", "blanchard")
    myCommand.ExecuteNonQuery()

    myTrans.Commit()
    Console.WriteLine("Both records are written to database.")
    Catch er As Exception
    -----------------------------------------------------------------------------
    this was adapted from msdn lib article
    ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1033/cpguide/html/cpconperformingtransactionusingadonet.htm

    as u can see in the article it dosnt actully use a stored procedure

    SO QUESTION IS how would u code it to call two stored procedures ? in the msdn lib example it shows to inserts statements string after each other i guess you do the same but how because the stored proc has been defined outside of the try and also cant define within the try because of the code structure

    PLEASE HELP
    I am curretly building a defect management system for software and web developers,
    If you wana try it out (beta test) and keep it for free just send me a message

  2. #2
    New Member
    Join Date
    Feb 2003
    Location
    Maputo, Moçambique
    Posts
    13
    Hello!

    What do you mean with "the stored proc has been defined outside of the try"? It is usually no special trick to use stored procedures in a transaction, you just execute them one after another.

    VB Code:
    1. Try
    2.   myCommand.CommandType = CommandType.StoredProcedure
    3.  
    4.   myCommand.CommandText = "StoredProcedure1"
    5.   myCommand.Parameters.Add("@firstname", "Carl")
    6.   myCommand.Parameters.Add("@surname", "Blanchard")
    7.   myCommand.ExecuteNonQuery()
    8.  
    9.   myCommand.CommandText = "StoredProcedure2"
    10.   myCommand.Parameters.Clear()
    11.   myCommand.Parameters.Add("@parameter2", parameter2)
    12.   myCommand.ExecuteNonQuery()
    13.  
    14.   myTrans.Commit()
    15.  
    16. Catch e as exception
    17.   myTrans.Rollback()

    /Sara

  3. #3

    Thread Starter
    Fanatic Member carlblanchard's Avatar
    Join Date
    Sep 2003
    Location
    Bournemouth (UK)
    Posts
    539

    hey sara

    its ok now sorted it

    .connection = myconnection

    cheers anyway
    Last edited by carlblanchard; Oct 22nd, 2003 at 05:45 AM.
    I am curretly building a defect management system for software and web developers,
    If you wana try it out (beta test) and keep it for free just send me a message

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