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. How to detect table lock

How to detect table lock

Scheduled Pinned Locked Moved Database
databasehelpsql-serversysadmintutorial
4 Posts 4 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 Smith IX
    wrote on last edited by
    #1

    Hi all, I have a database on SQL Server 2005, serving several clients. Some of my queries need more than 20 seconds to finish. Problem occurs when ClientA runs the query, and one second later ClientB runs it as well. Since the query involves some editing, it will lock the table for the duration of the query. So what usually happens is that ClientB will have "query timeout expired" error message because the request cannot be completed within the default 30 second query timeout. a. Is there any way to know whether a table/record is being locked, and by which computer? b. Can I change the default 30 seconds query timeout by code? Thanks a lot for any pointer.

    M A R 3 Replies Last reply
    0
    • J Joe Smith IX

      Hi all, I have a database on SQL Server 2005, serving several clients. Some of my queries need more than 20 seconds to finish. Problem occurs when ClientA runs the query, and one second later ClientB runs it as well. Since the query involves some editing, it will lock the table for the duration of the query. So what usually happens is that ClientB will have "query timeout expired" error message because the request cannot be completed within the default 30 second query timeout. a. Is there any way to know whether a table/record is being locked, and by which computer? b. Can I change the default 30 seconds query timeout by code? Thanks a lot for any pointer.

      M Offline
      M Offline
      Mycroft Holmes
      wrote on last edited by
      #2

      A. not easily - I would look at your workflow and query and try to isolate the part where the updates to the tables are done and split them into a seperate process from the rest of the query. B. Change the command timeout or the connection timeout.

      Never underestimate the power of human stupidity RAH

      1 Reply Last reply
      0
      • J Joe Smith IX

        Hi all, I have a database on SQL Server 2005, serving several clients. Some of my queries need more than 20 seconds to finish. Problem occurs when ClientA runs the query, and one second later ClientB runs it as well. Since the query involves some editing, it will lock the table for the duration of the query. So what usually happens is that ClientB will have "query timeout expired" error message because the request cannot be completed within the default 30 second query timeout. a. Is there any way to know whether a table/record is being locked, and by which computer? b. Can I change the default 30 seconds query timeout by code? Thanks a lot for any pointer.

        A Offline
        A Offline
        Ashfield
        wrote on last edited by
        #3

        You probably need to split your query down to isolate the actual updates, then the problem will be reduced. Take locks late and release early is the best advice I can give. You can increase the timeout on the command or connection.

        Bob Ashfield Consultants Ltd

        1 Reply Last reply
        0
        • J Joe Smith IX

          Hi all, I have a database on SQL Server 2005, serving several clients. Some of my queries need more than 20 seconds to finish. Problem occurs when ClientA runs the query, and one second later ClientB runs it as well. Since the query involves some editing, it will lock the table for the duration of the query. So what usually happens is that ClientB will have "query timeout expired" error message because the request cannot be completed within the default 30 second query timeout. a. Is there any way to know whether a table/record is being locked, and by which computer? b. Can I change the default 30 seconds query timeout by code? Thanks a lot for any pointer.

          R Offline
          R Offline
          Rutvik Dave
          wrote on last edited by
          #4

          I have also faced the same problem when i used multithreading with very complex query that takes 25 sec to execute. and there are multiple threads so they hit the sql server with the same query at a time which cause Time Out Expired... I think following might help you. You can view the Locks by executing**

          sp_lock

          Also try these undocumented system stored procedures to get the info about blocking.

          sp_who
          sp_who2

          **Read this MSDN KB Article and Try to divide the update/delete statement by block of rows like this [^]

          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