Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Bulk Update Fails

Bulk Update Fails

Scheduled Pinned Locked Moved Database
databasehelpsql-servervisual-studiocom
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Joe 2
    wrote on last edited by
    #1

    I am trying to run a bulk update on a table by picking up the IDs that I've populated onto a table variable based on some criteria. The update just works fine if the number of records in the table variable are < = 1000. When this number increases to 5000, the update does'nt work. When I try to debug my code, I get the message box stating "Error while executing 'A Batch Cmd' at line 0; Sql Error: 0 "The statement has been terminated." On catching this execption I get the message "Timeout expired.The Timeout period elasped prior to completion of the operation of the operation or the server is not responding.\r\n The statement has been terminated." When I try to run the stored proc from the query analyzer, it keeps processing for a long time and that I've to manually stop the execution. On trying to run the queries that I have in the stored proc individually did'nt yield me positive results either. I've ensured that my stored proc meets the specifications listed here[^] Can anyone throw some light on what can be tried to fix this? Environment: VS 2005 Pro, Sql Server 2000

    A M 2 Replies Last reply
    0
    • J Joe 2

      I am trying to run a bulk update on a table by picking up the IDs that I've populated onto a table variable based on some criteria. The update just works fine if the number of records in the table variable are < = 1000. When this number increases to 5000, the update does'nt work. When I try to debug my code, I get the message box stating "Error while executing 'A Batch Cmd' at line 0; Sql Error: 0 "The statement has been terminated." On catching this execption I get the message "Timeout expired.The Timeout period elasped prior to completion of the operation of the operation or the server is not responding.\r\n The statement has been terminated." When I try to run the stored proc from the query analyzer, it keeps processing for a long time and that I've to manually stop the execution. On trying to run the queries that I have in the stored proc individually did'nt yield me positive results either. I've ensured that my stored proc meets the specifications listed here[^] Can anyone throw some light on what can be tried to fix this? Environment: VS 2005 Pro, Sql Server 2000

      A Offline
      A Offline
      andyharman
      wrote on last edited by
      #2

      Can you post some of the code up here so we can take a look?

      J 1 Reply Last reply
      0
      • A andyharman

        Can you post some of the code up here so we can take a look?

        J Offline
        J Offline
        Joe 2
        wrote on last edited by
        #3

        andyharman wrote:

        Can you post some of the code up here

        Yes,sure. The following lists the logic and flow of my proc. .... Proc declarations go here ....

        Begin Transaction

        Declare @tblCategory Table (CategoryID BigInt)

        Insert into @tblCategory(CategoryID)
        Select A.CategoryID from Shop A Where ProductName = @pProdName

        If exists(select categoryId from @tblCategory)
        begin
        Declare @tblLocalities Table(CategoryID BigInt, LocalityID int)
        Insert into @tblLocalities (categoryid,localityid)
        select B.CategoryID, B.localityId from ShopGroup B, Shop A
        where A.CategoryID = B.CategoryID and A.ProductName = @pProdName

        If @@rowcount > 0
        begin
        Update Shop Set Ranking = 2 where categoryID in
        (select t.CategoryID from @tblLocalities t)
        end
        end
        If @@error > 0
        Begin
        rollback transaction
        end
        else
        begin
        commmit transaction
        end

        A 1 Reply Last reply
        0
        • J Joe 2

          I am trying to run a bulk update on a table by picking up the IDs that I've populated onto a table variable based on some criteria. The update just works fine if the number of records in the table variable are < = 1000. When this number increases to 5000, the update does'nt work. When I try to debug my code, I get the message box stating "Error while executing 'A Batch Cmd' at line 0; Sql Error: 0 "The statement has been terminated." On catching this execption I get the message "Timeout expired.The Timeout period elasped prior to completion of the operation of the operation or the server is not responding.\r\n The statement has been terminated." When I try to run the stored proc from the query analyzer, it keeps processing for a long time and that I've to manually stop the execution. On trying to run the queries that I have in the stored proc individually did'nt yield me positive results either. I've ensured that my stored proc meets the specifications listed here[^] Can anyone throw some light on what can be tried to fix this? Environment: VS 2005 Pro, Sql Server 2000

          M Offline
          M Offline
          Mike Dimmick
          wrote on last edited by
          #4

          Yes, inserting or updating a lot of records will take a lot of time, particularly if running other queries concurrently against the same records (which may temporarily block your updates due to locks). ADO.NET stops your application from being blocked forever by imposing a configurable command timeout, which you set in the SqlCommand's CommandTimeout property. It defaults to 30 seconds, so if your command takes more than 30 seconds to execute you get a SqlException. Management Studio assumes you're more interested in the results than in a speedy response and doesn't time out.


          DoEvents: Generating unexpected recursion since 1991

          J 1 Reply Last reply
          0
          • M Mike Dimmick

            Yes, inserting or updating a lot of records will take a lot of time, particularly if running other queries concurrently against the same records (which may temporarily block your updates due to locks). ADO.NET stops your application from being blocked forever by imposing a configurable command timeout, which you set in the SqlCommand's CommandTimeout property. It defaults to 30 seconds, so if your command takes more than 30 seconds to execute you get a SqlException. Management Studio assumes you're more interested in the results than in a speedy response and doesn't time out.


            DoEvents: Generating unexpected recursion since 1991

            J Offline
            J Offline
            Joe 2
            wrote on last edited by
            #5

            Mike Dimmick wrote:

            Yes, inserting or updating a lot of records will take a lot of time, particularly if running other queries concurrently against the same records

            Thanks on your views Mike. I will now need to figure out a way to fine tune my proc.

            Mike Dimmick wrote:

            Management Studio assumes you're more interested in the results than in a speedy response and doesn't time out

            Do we have any settings / system procs that will take care of the time-out issue in Sql Server 2000?

            1 Reply Last reply
            0
            • J Joe 2

              andyharman wrote:

              Can you post some of the code up here

              Yes,sure. The following lists the logic and flow of my proc. .... Proc declarations go here ....

              Begin Transaction

              Declare @tblCategory Table (CategoryID BigInt)

              Insert into @tblCategory(CategoryID)
              Select A.CategoryID from Shop A Where ProductName = @pProdName

              If exists(select categoryId from @tblCategory)
              begin
              Declare @tblLocalities Table(CategoryID BigInt, LocalityID int)
              Insert into @tblLocalities (categoryid,localityid)
              select B.CategoryID, B.localityId from ShopGroup B, Shop A
              where A.CategoryID = B.CategoryID and A.ProductName = @pProdName

              If @@rowcount > 0
              begin
              Update Shop Set Ranking = 2 where categoryID in
              (select t.CategoryID from @tblLocalities t)
              end
              end
              If @@error > 0
              Begin
              rollback transaction
              end
              else
              begin
              commmit transaction
              end

              A Offline
              A Offline
              andyharman
              wrote on last edited by
              #6

              I'm trying to understand what your code is trying to achieve. As far as I can work out, the following would do the same: UPDATE Shop SET Ranking = 2 WHERE CategoryID in ( SELECT B.CategoryID FROM Shop A INNER JOIN ShopGroup B ON A.CategoryID = B.CategoryID WHERE A.ProductName = @pProdName ) Is this any faster? How many rows does it update? What is the purpose of linking to "ShopGroup"? The next step would probably to look at the indexes. Regards Andy

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups