The EXECUTE permission was denied on the object 'xxxxxxx', database 'zzzzzzz', schema 'dbo'

后端 未结 14 1783
梦谈多话
梦谈多话 2020-12-02 05:18

I\'m having problems executing a function.

Here\'s what I did:

  1. Create a function using SQL Server Management Studio. It was successfully created.
相关标签:
14条回答
  • 2020-12-02 05:24

    here is how to give permission for one user not public,

    Direct Query:

    Use MyDatabase Grant execute on [dbo].[My-procedures-name] to [IIS APPPOOL\my-iis-pool] Go

    0 讨论(0)
  • 2020-12-02 05:26

    you'd better off modifying server roles, which was designed for security privileges. add sysadmin server role to your user. for better security you may have your custom server roles. but this approach will give you what you want for now.

    1. Object Explorer -> Server -> Security -> Logins
    2. Right click on your desired user
    3. Go to Server Roles on left hand side
    4. Make sure sysadmin is checked
    5. Hit OK and restart your SQL server

    Good luck

    0 讨论(0)
  • 2020-12-02 05:27

    The general answer is to grant execute permission as explained above. But that doesn't work if the schema owner of SP is different to underlying objects.

    Check schema owners by:

    select name, USER_NAME(s.principal_id) AS Schema_Owner from sys.schemas s
    

    To change the owner of an schema you can:

    ALTER AUTHORIZATION ON SCHEMA::YOUR_SCHEMA TO YOUR_USER;
    

    Examples:

    ALTER AUTHORIZATION ON SCHEMA::Claim TO dbo
    ALTER AUTHORIZATION ON SCHEMA::datix TO user1;
    

    Finally if within your SP you are truncating a table or changing structure you may want to add WITH EXECUTE AS OWNER in your SP:

    ALTER procedure [myProcedure] 
    WITH EXECUTE AS OWNER
    
    as
    
    truncate table etl.temp
    
    0 讨论(0)
  • 2020-12-02 05:32

    I have faced the same problem and I solved as give db_owner permission too to the Database user.

    0 讨论(0)
  • 2020-12-02 05:33

    You can give everybody execute permission:

    GRANT Execute on [dbo].your_object to [public]
    

    "Public" is the default database role that all users are a member of.

    0 讨论(0)
  • 2020-12-02 05:34

    If you have issues like the question ask above regarding the exception thrown when the solution is executed, the problem is permission, not properly granted to the users of that group to access the database/stored procedure. All you need do is to do something like what i have below, replacing mine with your database name, stored procedures (function)and the type of permission or role or who you are granting the access to.

    USE [StableEmployee]
    GO
    GRANT EXEC ON dbo.GetAllEmployees TO PUBLIC
    

    /****** Object: StoredProcedure [dbo].[GetAllEmployees] Script Date: 01/27/2016 16:27:27 ******/

    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    ALTER procedure [dbo].[GetAllEmployees]
    as
    Begin
    Select EmployeeId, Name, Gender, City, DepartmentId
    From tblEmployee
    
    End
    
    0 讨论(0)
提交回复
热议问题