sp_executesql - turn off

  • Hi,

     I wondered if someone could answer a question for me please

    Is it possible to turn off sp_executesql on a server? or is it just one of those things that should be properly managed by permissions and access?

    Thanks,
    Nic

  • Nic

    I don't think there's a setting whereby you can turn it on or off.  All members of the public role have access to the stored procedure, according to the documentation.  You could try denying EXECUTE on it to public.  I've never tried that myself, though.

    John

  • Thanks for the reply, you are correct running the following prevents execution.

    DENY EXECUTE ON sp_executesql TO testuser

    Thanks,

    Nic

  • That won't stop them using EXEC though:

    USE master;
    GO

    CREATE LOGIN TestLogin WITH PASSWORD = '123', CHECK_POLICY = OFF;
    GO
    CREATE USER TestLogin FOR LOGIN TestLogin;
    GO
    DENY EXECUTE ON sp_executesql TO TestLogin;
    GO

    EXECUTE AS LOGIN = 'TestLogin';
    GO
    DECLARE @SQL nvarchar(max) = N'SELECT 1';
    EXEC sp_executesql @SQL; --This fails
    GO
    DECLARE @SQL nvarchar(max) = N'SELECT 1';
    EXEC (@SQL); --This works
    GO
    REVERT

    GO
    DROP USER TestLogin;
    DROP LOGIN TestLogin;
    GO

    Thom~

    Excuse my typos and sometimes awful grammar. My fingers work faster than my brain does.
    Larnu.uk

  • I wouldn't deny execute on that procedure, but then I make extensive use of it myself in both scripts and stored procedures.

Viewing 5 posts - 1 through 4 (of 4 total)

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