Reputation: 62
We have a requirement for application (NextGen ERH) to work with SQL Server (2016, on-premises) DB under credentials with sysadmin role.
Our need is to prevent that tech user from setting DB to a single user mode - we noticed that sometimes such happens and would like to prevent future cases.
So, question is - how I may achieve it? Revoke alter any database from username
- didn't help, user is still able to set DB to a single user mode.
DB user is local to SQL server, not Windows authentication.
Upvotes: 0
Views: 1118
Reputation: 1657
If you want to prevent the entire database from single user mode you can use the following code
exec sp_dboption 'your_database_name_goes_here', 'single user', 'FALSE'
For sql server version greater than 2005
ALTER DATABASE 'your_database_name_goes_here' SET MULTI_USER
If you want the database to be set to single server mode only by sysadmin you can use the below code
ALTER DATABASE 'your_database_name_goes_here'
SET RESTRICTED_USER WITH ROLLBACK IMMEDIATE
If the tech user does not belongs to sysadmin role, then the above code will prevent him from setting the db to single user mode.
EDIT
To set a database to Multi-user mode using SSMS
Upvotes: 0