How to disable and enable the store procedure?

  • Hi All ,

    How to disable and enable the store procedure?

    cheers

  • I believe you cannot disable a stored procedure directly... but there are few ways to accomplish it...

    check these links...

    http://stackoverflow.com/questions/23114386/enable-disable-stored-procedures

    https://go4answers.webhost4life.com/Example/disable-stored-procedure-149295.aspx

    ______________________________________________________________Every Problem has a Solution; Every Solution has a Problem: 🙂

  • karthik babu (9/15/2014)


    I believe you cannot disable a stored procedure directly... but there are few ways to accomplish it...

    check these links...

    http://stackoverflow.com/questions/23114386/enable-disable-stored-procedures

    https://go4answers.webhost4life.com/Example/disable-stored-procedure-149295.aspx

    so can I uncheck the GRANt permission for EXECUTE ( Via right click and properties ) in that Store proc ?

  • Better use the sample code below..

    REVOKE EXECUTE ON OBJECT::dbo.StoredProcedure

    FROM LoginName;

    GO

    ______________________________________________________________Every Problem has a Solution; Every Solution has a Problem: 🙂

  • karthik babu (9/15/2014)


    Better use the sample code below..

    REVOKE EXECUTE ON OBJECT::dbo.StoredProcedure

    FROM LoginName;

    GO

    Dont u think it is the same like : uncheck the GRANT and Check the DENY ??

  • I tried the same and its not reflecting in the GUI. I go by the SQL Query.

    ______________________________________________________________Every Problem has a Solution; Every Solution has a Problem: 🙂

  • WhiteLotus (9/14/2014)


    Hi All ,

    How to disable and enable the store procedure?

    cheers

    Quick question, by disabling it do you mean make it do nothing, make it disappear from the user's view or block execution of it?

    😎

  • Eirikur Eiriksson (9/15/2014)


    WhiteLotus (9/14/2014)


    Hi All ,

    How to disable and enable the store procedure?

    cheers

    Quick question, by disabling it do you mean make it do nothing, make it disappear from the user's view or block execution of it?

    😎

    make it do nothing because the queue is very high so i need to disable and enable it after a period of time

  • WhiteLotus (9/15/2014)


    Eirikur Eiriksson (9/15/2014)


    WhiteLotus (9/14/2014)


    Hi All ,

    How to disable and enable the store procedure?

    cheers

    Quick question, by disabling it do you mean make it do nothing, make it disappear from the user's view or block execution of it?

    😎

    make it do nothing because the queue is very high so i need to disable and enable it after a period of time

    Then Grant/Revoke is out of the question, would most likely cause errors in the caller code. Possibly the best options are:

    a. Create a table or use on if it exists to control the execution, a flag can be toggled active/inactive and at the start of the execution, the procedure reads the flag.

    b. Use time driven logic, i.e. conditional in the procedure makes it exit every odd number of minutes.

    c. Add the logic in the caller code and leave the procedure unchanged.

    😎

  • I'd think the easiest way to do this would be to cheat. Rename it. Then name it back.

    But, that could cause errors in the code if it tries to call the proc and it's not there. But, then again, if you revoke access to the proc, you're going to see a similar error.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • This might be kind of silly but just alter the procedure with all the code commented out, that will effectively disable it, then when you want to turn it back on just alter it again with the code uncommented.

    That would be relatively straight forward to set up as a scheduled job and wouldn't create any application errors.

  • WhiteLotus (9/15/2014)


    Eirikur Eiriksson (9/15/2014)


    WhiteLotus (9/14/2014)


    Hi All ,

    How to disable and enable the store procedure?

    cheers

    Quick question, by disabling it do you mean make it do nothing, make it disappear from the user's view or block execution of it?

    😎

    make it do nothing because the queue is very high so i need to disable and enable it after a period of time

    The stored proc is code - it sounds like you really want to disable whatever is calling it. Why not disable the job that is calling this code?

    ----------------------------------------------------------------------------------
    Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?

  • All of those seem far too disruptive to me.

    Two quick possibilities:

    1) Add an optional parameter to the proc which requires a certain value or the proc just exits (or does whatever limited processing you want and then exits). When you want the proc to run normally, set the default for that param to the required value: voila, everyone can use proc fully.

    When you don't want the proc to be active (except as you specifically require it to be), alter the proc so the default is a non-matching value, and thus the caller must pass in the correct value to get the full proc to run.

    2) Use byte(s) in CONTEXT_INFO() to have the same effect. This is more involved to get working correctly, but can work as well.

    I strongly urge you not to just REVOKE all permissions, since there's no easy way to put them all back. Or to rename the proc, which would force recompiles of already compiled code, and possibly outright errors in other cases.

    SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".

  • Grant Fritchey (9/15/2014)


    I'd think the easiest way to do this would be to cheat. Rename it. Then name it back.

    But, that could cause errors in the code if it tries to call the proc and it's not there. But, then again, if you revoke access to the proc, you're going to see a similar error.

    At first I thought you were joking as it would certainly raise error in the caller code but then the bulb started to flicker, with ProcA(working) and ProcB(empty), swap names with a three step renaming, A to C, B to A and C to B;-)

    😎

  • Eirikur Eiriksson (9/15/2014)


    Grant Fritchey (9/15/2014)


    I'd think the easiest way to do this would be to cheat. Rename it. Then name it back.

    But, that could cause errors in the code if it tries to call the proc and it's not there. But, then again, if you revoke access to the proc, you're going to see a similar error.

    At first I thought you were joking as it would certainly raise error in the caller code but then the bulb started to flicker, with ProcA(working) and ProcB(empty), swap names with a three step renaming, A to C, B to A and C to B;-)

    😎

    I'm not joking. I'm not crazy about the solution either, but I sure wouldn't want to try to remove the privs and add them back, or modify the procedure and then unmodify it in some manner. It feels like renaming is less intrusive, although, again, it's sure to raise an error in the app, which also makes me uncomfortable.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

Viewing 15 posts - 1 through 15 (of 21 total)

You must be logged in to reply to this topic. Login to reply