Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Granting Execute Permission on SQL Azure

I recently migrated a database to SQL Azure. When I try to execute a stored procedure on this database on SQL Azure, I receive the following error:

The EXECUTE permission was denied on the object 'Log_Save', database 'MyDatabase', schema 'dbo'.

My question is, how do I grant EXECUTE permissions to stored procedures (as well as read/write access to tables) on SQL Azure?

thank you!

like image 747
user70192 Avatar asked Apr 03 '12 11:04

user70192


People also ask

How do I grant Permissions in SQL?

To grant permissions for the user, switch to the Object Permissions tab. In the Objects block, select the database object on which you want to grant privileges. In the Available Privileges block, select the permissions to be assigned and click Save.

How do I check for execute Permissions in SQL Server?

SQL Server includes a very useful system function sys. fn_my_permissions to list all the permissions of a particular principal (user or login) and this system function will help you list all permissions of a principal on a specific database object (securable).


2 Answers

Related to Joe Abrams' answer, you can grant execute permission to an individual user:

GRANT EXECUTE TO testuser
GO
like image 100
user1651370 Avatar answered Sep 18 '22 19:09

user1651370


The trick is that you have to create a custom "executor" role and then grant execute permissions to it.

In your master DB, first create a user if you don't have one already:

CREATE USER MyUser FOR LOGIN MyLogin WITH DEFAULT_SCHEMA=[dbo]
GO

Then, in your new DB:

CREATE ROLE [db_executor] AUTHORIZATION [dbo]
GO

GRANT EXECUTE TO [db_executor]
GO

sp_addrolemember @rolename = 'db_executor', @membername = 'MyUser'
sp_addrolemember @rolename = 'db_datareader', @membername = 'MyUser'
sp_addrolemember @rolename = 'db_datawriter', @membername = 'MyUser'
like image 40
Joe Abrams Avatar answered Sep 21 '22 19:09

Joe Abrams