148

I moved a database from SQL Server 2012 to Azure. I don't want to use the user master, so I created a user test. This is what I did for database XXX on Azure:

create user test from login test with default_schema=[dbo]
exec sp_addrolemember 'db_owner','test'

I checked, and the database objects I am interested in are all in the schema dbo. The table Users is in the schema dbo.

The connection string in my web project has test as the login. It produces the error message:

The SELECT permission was denied on the object 'Users', database 'XXX', schema 'dbo'

What does the error message mean and what can I do to let user test access the database XXX?

1
  • Thanks for asking this question :)
    – Kamlesh
    Commented Aug 21, 2019 at 15:36

11 Answers 11

165
  1. Open SQL Management Studio
  2. Expand your database
  3. Expand the "Security" Folder
  4. Expand "Users"
  5. Right click the user (the one that's trying to perform the query) and select Properties.
  6. Select page Membership.
  7. Make sure you uncheck

    db_denydatareader

    db_denydatawriter

enter image description here

This should go without saying, but only grant the permissions to what the user needs. An easy lazy fix is to check db_owner like I have, but this is not the best security practice.

2
  • 8
    Many of us simply select all of them by assumption that we will get all permissions. However there is a deny too Commented Nov 5, 2020 at 11:21
  • 2
    In SSMS 18, the users are found in the Logins folder, and the membership toggling is found under User mapping.
    – Astrid E.
    Commented Dec 6, 2022 at 11:27
94

I think the problem is with the user having deny privileges. This error comes when the user which you have created does not have the sufficient privileges to access your tables in the database. Do grant the privilege to the user in order to get what you want.

GRANT the user specific permissions such as SELECT, INSERT, UPDATE and DELETE on tables in that database.

3
  • 3
    Sometimes you will be missing db data reader /db owner options ? windowstechinfo.com/2014/09/…
    – Aravinda
    Commented Apr 13, 2015 at 4:35
  • 5
    I had to uncheck 'db_denydatareader' and 'db_denydatawriter' and I guess that is what SaeX means by "revoke". Thanks SaeX.
    – AH.
    Commented Oct 14, 2016 at 14:21
  • @AH. I had the same problem as you, so I wrote an answer to this question. Check it out if you get a chance Commented Aug 14, 2018 at 18:37
51

The syntax to grant select permission on a specific table :

USE YourDB;

GRANT SELECT ON dbo.functionName TO UserName;

To grant the select permission on all tables in the database:

USE YourDB;

GRANT SELECT TO UserName;
2
  • 2
    First time I've done this so I'm not sure if it was correct, but I wanted to Grant select permission for the whole database so I did GRANT SELECT TO UserName and left off the ON clause. It worked.
    – Rich
    Commented Mar 2, 2018 at 20:49
  • This worked for me with a SQL Server database hosted on Azure. The top voted answer (where you right click the user and select properties) didn't work because there was no properties option.
    – user20204585
    Commented Nov 3, 2022 at 12:42
21

This is how I was able to solve the problem when I faced it

  1. Start SQL Management Studio.
  2. Expand the Server Node (in the 'Object Explorer').
  3. Expand the Databases Node and then expand the specific Database which you are trying to access using the specific user.
  4. Expand the Users node under the Security node for the database.
  5. Right click the specific user and click 'properties'. You will get a dialog box.
  6. Make sure the user is a member of the db_owner group (please read the comments below before you use go this path) and other required changes using the view. (I used this for 2016. Not sure how the specific dialog look like in other version and hence not being specific)
8
  • 6
    Be careful who you put into the db_owner database role. Not all users should be added to that role.
    – Rod
    Commented May 2, 2017 at 20:06
  • 1
    @Rod If granting the db_owner is not recommended, then which access type is recommended for the application to interact with the database?
    – Jacob
    Commented Aug 17, 2017 at 22:13
  • 1
    Would public suffice?
    – Rod
    Commented Aug 22, 2017 at 15:25
  • 2
    @Jacob To write and read data in any table there id db_datareader and db_datawriter. db_owner also gives permission to modify table definitions. Commented Jun 6, 2018 at 8:01
  • 4
    This doesn't work if the user has checked db_denydatareade or db_denydatawriter Commented Aug 14, 2018 at 18:36
0

Grant permissions for that user is needed

0

Check space of your database.this error comes when space increased compare to space given to database.

1
  • Also Change the database Userid and password
    – Nilesh
    Commented Jun 24, 2015 at 6:13
0

Using SSMS, I made sure the user had connect permissions on both the database and ReportServer.

On the specific database being queried, under properties, I mapped their credentials and enabled datareader and public permissions. Also, as others have stated-I made sure there were no denyread/denywrite boxes selected.

I did not want to enable db ownership when for their reports since they only needed to have select permissions.

0

I had just, for the first time, used the Plesk panel on my website hosting service to download an "Export Dump" file of my hosted SQL Server database.

After needing to use a different StackOverflow Question/Answer to understand how to use what I had downloaded, then in SQL Server Management studio I went into Security | Logins and pointed one of the Logins to the new local database I now had and tried to run my app. I got the error message in this Question (except my error message mentioned 'Keys' rather than 'Users').

So then, I followed the Answer provided here by Kellen Stuart, and it was a help for sure. The difference in my situation was, instead of the login having all the Database roles checked, my login had none of the roles checked.

So for my purposes (developing an app on my local workstation) I just needed to check db_owner, and I was good to go.

0

as others said you need to set a grant for your user and tables and in conclusion for your database. you have to solve your problem with UI as bellow image. with this technic you must set some permissions(CRUD) to your specific user and finally your user can use that really easy.

The SELECT permission was denied on the object 'Users', database 'Xyz', schema 'dbo' ;

enter image description here

-2

I resolve my problem doing this. [IMPORTANT NOTE: It allows escalated (expanded) privileges to the particular account, possibly more than are needed for individual scenario].

  1. Go to 'Object Explorer' of SQL Management Studio.
  2. Expand Security, then Login.
  3. Select the user you are working with, then right click and select Properties Windows.
  4. In Select a Page, Go to Server Roles
  5. Click on sysadmin and save.
6
  • 2
    Not sure, why this answer was downvoted. This answer solved my problem. So, I have upvoted. Commented Mar 5, 2018 at 9:08
  • 22
    This answer SHOULD be downvoted because it blatantly tells the reader to give the user object full, complete and total control of the entire server without explaining or warning that this is what it does. Based on the wording of the question and this reply, I think there is some danger that novice users will apply this "fix" without understanding fully. Commented Jun 6, 2018 at 8:00
  • 6
    This is a brute force option that should not be applied. If you don't understand what this is doing then you shouldn't be doing it.
    – n8.
    Commented Nov 2, 2018 at 22:38
  • 2
    Everyone - do not do this in production environment.
    – gotqn
    Commented Apr 16, 2019 at 12:45
  • Of course I wouldn't do that in prod but it solved my problem (in dev environment). So it deserves my upvote. Thanks ccassob.
    – Fl4v
    Commented May 11, 2020 at 15:06
-2

May be your Plesk panel or other panel subscription has been expired....please check subscription End.

1
  • Please provide some more description around your answer
    – asolanki
    Commented Mar 6, 2020 at 4:22

Not the answer you're looking for? Browse other questions tagged or ask your own question.