Results 1 to 11 of 11

Thread: ADO Transactions with SQLSERVER(??)

Hybrid View

  1. #1

    Thread Starter
    Lively Member amolt's Avatar
    Join Date
    Aug 2006
    Location
    INDIA
    Posts
    80

    Unhappy Re: ADO Transactions with SQLSERVER(??)

    Hi szlamany,
    You are correct to use action querys in simple updates.
    But its my need to rollback the transactions too.
    Also if I use simple updates the record which is updated and for which the local process is still running, have been seen by the client and thus lead to misbehaviour.

    Regds,

  2. #2
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: ADO Transactions with SQLSERVER(??)

    Then there is an answer to that issue as well.

    Most people don't want to think set-based - it's so much easier to program in an iterative fashion.

    But to truly utilize SQL you must always be set-based.

    The simple set-based solution to your problem is to load a temp table with the new data first. MS SQL offer bulk insert options - both at command line and also part of the SQL Client - to get that data loaded in one shot.

    Once you get the data into a temp table you can do a single UPDATE statement to process all rows.

    We do this in literally hundreds of places - loading all kinds of data in these ways.

    Expecting to use transactions to manage errors and then do rollbacks is not appropriate.

    You should be creating temp tables.

    Then you could delete the rows that aren't good to load.

    Then you could do the UPDATE all in one step - syntax would be something like this.

    Code:
    Update MyTable Set Column1=TT.Column1, Column2=TT.Column2
       From #TempTable TT
       Left Join MyTable MT on MT...=TT...
       Where {some great condition statement to make sure the UPDATE will not fail}
    Taking data into VB to be processed one row at a time in a multi-user environment is a poor choice when you have other set-based "single" shot ACTION QUERY abilities that fully respect set-based logic.

    If you want assistance with doing this in a set-based fashion step back and tell us what you are trying to actually achieve. What the source of the data is - a couple of columns of sample data - and you will be amazed at how easy this can be done without looping through rows in VB and causing deadlock issues with your database

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

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