Login or Sign Up to become a member!
LessThanDot Sit Logo

LessThanDot

Data Management

Less Than Dot is a community of passionate IT professionals and enthusiasts dedicated to sharing technical knowledge, experience, and assistance. Inside you will find reference materials, interesting technical discussions, and expert tips and commentary. Once you register for an account you will have immediate access to the forums and all past articles and commentaries.

LTD Social Sitings

Lessthandot twitter Lessthandot Linkedin Lessthandot friendfeed Lessthandot facebook Lessthandot rss

Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.

Your profile

    Search

    XML Feeds

    Google Ads

    « 2011 Quarter 1 Goal ReviewThink about your presentation and who reviews it »
    comments

    SQL Server Management Studio will sometimes show a lock next to a stored procedure, there are several reasons why this might happen.

    The procedure is encrypted
    The procedure is a CLR stored procedure
    The user doesn't have the view definition permission for a stored proc

    Let's take a look at how this all works.

    I will first create this database with two stored procedures, one is encrypted, the other one is not

    1. CREATE DATABASE bla
    2. GO
    3.  
    4. USE bla
    5. GO
    6.  
    7. CREATE PROCEDURE prTest
    8. AS
    9. SELECT GETDATE()
    10. GO
    11.  
    12. CREATE PROCEDURE prTestEncrypted WITH ENCRYPTION
    13. AS
    14. SELECT GETDATE()
    15. GO

    Now when I navigate to the Stored Procedures folder I see the following

    As you can see there is a lock on the encrypted stored procedure

    Now, let's create a new user with data reader and writer permissions

    1. USE [master]
    2. GO
    3. CREATE LOGIN [test] WITH PASSWORD=N'test', DEFAULT_DATABASE=[bla], CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF
    4. GO
    5. USE [bla]
    6. GO
    7. CREATE USER [test] FOR LOGIN [test]
    8. GO
    9. USE [bla]
    10. GO
    11. EXEC sp_addrolemember N'db_datareader', N'test'
    12. GO
    13. USE [bla]
    14. GO
    15. EXEC sp_addrolemember N'db_datawriter', N'test'
    16. GO

    When I now login as that user I don't see anything under the stored procedures folder.



    In order to see the procedures, the user has to have execute permissions.
    If I give execute permissions to the stored procedures for the user like this, the user should see them.

    1. GRANT EXECUTE ON prTestEncrypted TO test
    2. GRANT EXECUTE ON prTest TO test

    The user will now see both procs with a lock on them

    If I grant view definition to the user....

    1. GRANT VIEW DEFINITION ON prTestEncrypted TO test
    2. GRANT VIEW DEFINITION ON prTest TO test

    The user will now see the lock only on the encrypted stored procedures, just like if he/she was a db owner

    I think there should be different lock icons in SSMS, this way you will now if the proc is encrypted or that you don't have view definition permissions...what do you think?



    *** Remember, if you have a SQL related question, try our Microsoft SQL Server Programming forum or our Microsoft SQL Server Admin forum

    About the Author

    User bio imageDenis has been working with SQL Server since version 6.5. Although he worked as an ASP/JSP/ColdFusion developer before the dot com bust, he has been working exclusively as a database developer/architect since 2002. In addition to English, Denis is also fluent in Croatian and Dutch, but he can curse in many other languages and dialects (just ask the SQL optimizer) He lives in Princeton, NJ with his wife and three kids.
    Social SitingsTwitterFacebookLinkedInHomePageFlickrLTD RSS Feed
    1906 views
    Instapaper

    2 comments

    Comment from: Picatrix [Member] Email
    Picatrix Interesting, I did not know this..thanks
    04/06/11 @ 10:47
    Comment from: Keith Mescha [Visitor] · http://kmescha.wordpress.org
    Keith Mescha I actually ran into this today as well. I saw the lock and figured out after some research that these procs were part of a Service Broker Queue Activation. Would this fall under the CLR pieces you described above?

    http://msdn.microsoft.com/en-us/library/ms190495(v=SQL.90).aspx
    04/06/11 @ 21:13

    Leave a comment


    Your email address will not be revealed on this site.

    Your URL will be displayed.
    (Line breaks become <br />)
    (Name, email & website)
    (Allow users to contact you through a message form (your email will not be revealed.)