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. Require a single instance of a Stored Procedure

Require a single instance of a Stored Procedure

Scheduled Pinned Locked Moved Database
databasequestionsql-serversysadminhelp
4 Posts 2 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.
  • A Offline
    A Offline
    Antony M Kancidrowski
    wrote on last edited by
    #1

    Using Microsoft SQL 2005 Express I need to be able to prevent the same stored procedure from running more than once at the same time so that if the stored procedure is in progress it does not run again. Although nothing will break if this occurs the second run will be redundant. I would like to ensure that any unnecessary work performed by the SQL Server is prevented. The Stored Procedure in question performs some housekeeping functionality that has a non-deterministic duration. I would like to do this all within SQL 2005 Express. Any help is appreciated. Thank you in advance for your time.

    Ant. **I'm hard, yet soft.
    I'm coloured, yet clear.
    I'm fruity and sweet.
    I'm jelly, what am I? Muse on it further, I shall return!

    **- David Walliams (Little Britain)

    W 1 Reply Last reply
    0
    • A Antony M Kancidrowski

      Using Microsoft SQL 2005 Express I need to be able to prevent the same stored procedure from running more than once at the same time so that if the stored procedure is in progress it does not run again. Although nothing will break if this occurs the second run will be redundant. I would like to ensure that any unnecessary work performed by the SQL Server is prevented. The Stored Procedure in question performs some housekeeping functionality that has a non-deterministic duration. I would like to do this all within SQL 2005 Express. Any help is appreciated. Thank you in advance for your time.

      Ant. **I'm hard, yet soft.
      I'm coloured, yet clear.
      I'm fruity and sweet.
      I'm jelly, what am I? Muse on it further, I shall return!

      **- David Walliams (Little Britain)

      W Offline
      W Offline
      Wendelius
      wrote on last edited by
      #2

      Hi, You could use locking for this. Create a small table and insert a single row in it. In the beginning of the procedure, update the row in the table to acquire lock and in the end of the procedure commit your changes. For example:

      CREATE TABLE ProcedureRun (LastRun datetime);
      INSERT INTO ProcedureRun (LastRun) VALUES (NULL);
      CREATE PROCEDURE SomeProcedure AS
      BEGIN
      UPDATE ProcedureRun SET LastRun = GETDATE();

      ... do some stuff...

      COMMIT;
      END;

      Hope this helps, Mika

      A 1 Reply Last reply
      0
      • W Wendelius

        Hi, You could use locking for this. Create a small table and insert a single row in it. In the beginning of the procedure, update the row in the table to acquire lock and in the end of the procedure commit your changes. For example:

        CREATE TABLE ProcedureRun (LastRun datetime);
        INSERT INTO ProcedureRun (LastRun) VALUES (NULL);
        CREATE PROCEDURE SomeProcedure AS
        BEGIN
        UPDATE ProcedureRun SET LastRun = GETDATE();

        ... do some stuff...

        COMMIT;
        END;

        Hope this helps, Mika

        A Offline
        A Offline
        Antony M Kancidrowski
        wrote on last edited by
        #3

        Thank you Mika, I have decided to take your advise. The concept of creating a "control table" seems a good one.

        Ant. **I'm hard, yet soft.
        I'm coloured, yet clear.
        I'm fruity and sweet.
        I'm jelly, what am I? Muse on it further, I shall return!

        **- David Walliams (Little Britain)

        W 1 Reply Last reply
        0
        • A Antony M Kancidrowski

          Thank you Mika, I have decided to take your advise. The concept of creating a "control table" seems a good one.

          Ant. **I'm hard, yet soft.
          I'm coloured, yet clear.
          I'm fruity and sweet.
          I'm jelly, what am I? Muse on it further, I shall return!

          **- David Walliams (Little Britain)

          W Offline
          W Offline
          Wendelius
          wrote on last edited by
          #4

          You're welcome :) Mika

          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