Granting User Database Permissions

cenko2 41 Reputation points
2022-03-22T21:37:12.8+00:00

We created a database user which has a default schema other than dbo in SQL Server 2016. It will only have DDL and DML permissions to the default schema. And this user will also be used in Azure DevOps to deploy a dacpac change using sqlpackage utility to the default schema. It has been given deny permissions in the dbo schema. Below are the current permissions of the user.

185763-image.png

However, when trying to create a table within the default schema, it gave the following error:
"VIEW SERVER STATE permission was denied on object 'server', database 'master'.
The user does not have permission to perform this action."

Why would it need the VIEW SERVER STATE permission when it already has a CREATE permission granted to it?

Any suggestions to accomplish the requirements above is much appreciated.

SQL Server | Other
{count} votes

Answer accepted by question author
  1. Erland Sommarskog 128.7K Reputation points MVP Volunteer Moderator
    2022-03-22T22:33:20.367+00:00

    Sounds like there is a DDL trigger. Check

    SELECT * FROM sys.triggers WHERE parent_class_desc = 'DATABASE'
    SELECT *FROM sys.server_triggers
    

    Run these queries with an account that is sysadmin.


4 additional answers

Sort by: Most helpful
  1. Erland Sommarskog 128.7K Reputation points MVP Volunteer Moderator
    2022-03-22T22:07:12.827+00:00

    Apparently sqlpackage performs an action which requires VIEW SERVER STATE. That's a server-level permission which does not come with CREATE permissions on a schema.

    What action sqlpackage is attempting to perform, I don't know, and I don't use sqlpackage myself. But you could use Profiler to spy on it. Capture the events RPC:Starting, SQL:BatchStarting and Error:Exception.

    0 comments No comments

  2. cenko2 41 Reputation points
    2022-03-22T22:28:08.213+00:00

    Thanks for your response, @Erland Sommarskog .

    But I was not using sqlpackage.exe to create the table, just running a simple CREATE TABLE statement on SSMS logged on as the user.

    0 comments No comments

  3. cenko2 41 Reputation points
    2022-03-22T22:41:34.967+00:00

    I ran the queries above and you are right, there are triggers in the database and server.

    Thank you!

    0 comments No comments

  4. CathyJi-MSFT 22,401 Reputation points Microsoft External Staff
    2022-03-23T07:25:02.14+00:00

    Hi @cenko2 ,

    VIEW SERVER STATE Permission is high level server-level privilege which must not be granted to everybody. Only administrators must have privilege to use view server state permission but we can assign this permission to some users who want to see server level state of your SQL Server instance.

    According to your error message, the login you are using to execute the script doesn’t have this permission. To fix this issue we will use admin account to grant view server state permission to the login name.

    USE MASTER  
    GO  
    GRANT VIEW SERVER STATE TO [username]  
    

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.