Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The EXECUTE permission was denied on the object 'zzzzzz, database 'xxxxxx' schema 'yyyyyy', [duplicate]

Tags:

sql-server

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.
  2. I then tried executing the newly created function and here's what I get:

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

like image 557
upendra parmar Avatar asked Sep 14 '10 11:09

upendra parmar


People also ask

How do I check for execute permissions in SQL Server?

Right click on your procedure and select Properties. You'll get the following window. As shown inthe preceding image, go to Permissions tab and click on Search button. On click you'll get a window to select user and roles, click on Browse to select users that require permission and click OK.

Does Db_owner have execute permission?

Btw, db_owner is a database ROLE in SQL Server , not a permission. Or if you want the user to execute all current and future stored procedures and scalar-valued functions: grant execute on schema::dbo to User for a single schema, or just grant execute to User for the whole database.

How do I grant permission to run a database in SQL Server?

Use SQL Server Management Studio From Stored Procedure Properties, select the Permissions page. To grant permissions to a user, database role, or application role, select Search. In Select Users or Roles, select Object Types to add or clear the users and roles you want.


10 Answers

Sounds like you need to grant the execute permission to the user (or a group that they a part of) for the stored procedure in question.

For example, you could grant access thus:

USE zzzzzzz;
GRANT EXEC ON dbo.xxxxxxx TO PUBLIC
like image 127
Rowland Shaw Avatar answered Oct 19 '22 23:10

Rowland Shaw


Best solution that i found is create a new database role i.e.

CREATE ROLE db_executor;

and then grant that role exec permission.

GRANT EXECUTE TO db_executor;

Now when you go to the properties of the user and go to User Mapping and select the database where you have added new role,now new role will be visible in the Database role membership for: section

For more detail read full article

like image 34
kazim Avatar answered Oct 20 '22 00:10

kazim


In SQL Server Management Studio, go to security->schema->dbo:

enter image description here

Double-click dbo, select the Permissions page, then click the "View database permissions" link in blue:

enter image description here

Select the user for whom you want to change permissions, and look for the "Execute" permission under the "explicit" tab:

enter image description here

Choose the appropriate permission by checking the appropriate box.

like image 41
Suhail Mumtaz Awan Avatar answered Oct 20 '22 00:10

Suhail Mumtaz Awan


you need to run something like this

GRANT Execute ON [dbo].fnc_whatEver TO [domain\user]
like image 29
Iain Avatar answered Oct 20 '22 00:10

Iain


This will work if you are trying to Grant permission to Users or roles.

Using Microsoft SQL Server Management Studio:

  1. Go to: Databases
  2. Right click on dbo.my_database
  3. Choose: Properties
  4. On the left side panel, click on: Permissions
  5. Select the User or Role and in the Name Panel
  6. Find Execute in in permissions and checkmark: Grant,With Grant, or Deny
like image 36
csebryam Avatar answered Oct 20 '22 00:10

csebryam


Giving such permission can be dangerous, especially if your web application uses that same username.

Now the web user (and the whole world wide web) also has the permission to create and drop objects within your database. Think SQL Injection!

I recommend granting Execute privileges only to the specific user on the given object as follows:

grant execute on storedProcedureNameNoquotes to myusernameNoquotes

Now the user myusernameNoquotes can execute procedure storedProcedureNameNoquotes without other unnecessary permissions to your valuable data.

like image 28
AMAR PANRAY Avatar answered Oct 20 '22 00:10

AMAR PANRAY


You don't have the right to execute it, although you have enough permissions to create it.

For more information, see GRANT Object Permissions (Transact-SQL)

like image 35
Denis Valeev Avatar answered Oct 20 '22 00:10

Denis Valeev


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
like image 30
Okwo moses Avatar answered Oct 19 '22 23:10

Okwo moses


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

like image 44
Mando Basha Avatar answered Oct 19 '22 23:10

Mando Basha


If you make this user especial for a specific database, then maybe you do not set it as db_owner in "user mapping" of properties

like image 22
Fatemeh M. Rezaie Avatar answered Oct 19 '22 23:10

Fatemeh M. Rezaie