Results 1 to 4 of 4

Thread: Transactions with Dao on SQL-Server

  1. #1

    Thread Starter
    Frenzied Member swatty's Avatar
    Join Date
    Aug 2002
    Location
    somewhere on earth
    Posts
    1,478

    Transactions with Dao on SQL-Server

    How can i use transactions on SQL-Server wiht DAO ?

    I am working on an access mdb which must be transfered to sql db instead of access db.

    Most updates and data access was writing using docmd's and dlookups , dmax, dcount.

    When using same code on sql-server i encouter problems with locks on tables.Where I get a sql-server timeout error.

    My boss wants DAO is still used so I can't change it to ADO.

    Anyone know how to use dao with transactions ??
    Code:
    If Question = Incomplete Then
       AnswerNextOne
    Else
       ReplyIfKnown
    End If
    cu Swatty

  2. #2
    Frenzied Member PilgrimPete's Avatar
    Join Date
    Feb 2002
    Posts
    1,313
    Take a look at the BeginTrans, CommitTrans and Rollback methods of the Workspace object.

  3. #3

    Thread Starter
    Frenzied Member swatty's Avatar
    Join Date
    Aug 2002
    Location
    somewhere on earth
    Posts
    1,478
    Someone has a sample on how to use this.

    I call different routines from a sub where different actions must be done on same db.

    Find nothing usefull on previous answer.
    Code:
    If Question = Incomplete Then
       AnswerNextOne
    Else
       ReplyIfKnown
    End If
    cu Swatty

  4. #4
    Frenzied Member PilgrimPete's Avatar
    Join Date
    Feb 2002
    Posts
    1,313
    Nothing at all?

    Does this help any..?

    VB Code:
    1. Private Sub TransactionTest()
    2. On Error GoTo TransactionTest_Error
    3.     Dim ws As DAO.Workspace
    4.     Dim cn As DAO.Connection
    5.     Dim db As DAO.Database
    6.     Dim bCommit As Boolean
    7.    
    8.     'create an ODBC direct workspace
    9.     Set ws = DBEngine.CreateWorkspace("testws", "", "", dbUseODBC)
    10.     Workspaces.Append ws
    11.     'begin the transaction
    12.     ws.BeginTrans
    13.    
    14.     'open a database using a DSN
    15.     Set db = ws.OpenDatabase("test")
    16.    
    17.     'make some changes
    18.     db.Execute ("UPDATE myTable SET Name = 'Pilgrim' WHERE PersonID='abc123'")
    19.     db.Execute ("UPDATE myTable SET Name = 'Pete' WHERE PersonID='def123'")
    20.    
    21.    
    22.    
    23. TransactionTest_Exit:
    24.     'shall we commit the changes?
    25.     If bCommit Then
    26.         ws.CommitTrans
    27.     End If
    28.     'tidy up
    29.     db.Close
    30.     ws.Close
    31.     Set db = Nothing
    32.     Set ws = Nothing
    33.     Exit Sub
    34. TransactionTest_Error:
    35.     ws.Rollback
    36.     Resume TransactionTest_Exit
    37. End Sub

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