How to restrict user to access database in MS SQL
RESTRICTED_USER allows for only members of the db_owner fixed
database role and dbcreator and sysadmin fixed server roles to connect
to the database, but does not limit their number. All connections to
the database are disconnected in the timeframe specified by the
termination clause of the ALTER DATABASE statement. After the database
has transitioned to the RESTRICTED_USER state, connection attempts by
unqualified users are refused.
RESTRICTED_USER allows for only members of the db_owner fixed database role and dbcreator and sysadmin fixed server roles to connect to the database, but does not limit their number. All connections to the database are disconnected in the timeframe specified by the termination clause of the ALTER DATABASE statement. After the database has transitioned to the RESTRICTED_USER state, connection attempts by unqualified users are refused.
Syntax is as follows:
alter database dbname
set RESTRICTED_USER
Link available on - http://blog.sanketik.com/index.php/how-to-restrict-user-to-access-database-in-ms-sql/
More detailed information is available at - http://www.blackwasp.co.uk/SQLRestrictedUser.aspx
Setting Database to Single User Mode
Keep query window open after running this. This will kick users off db after 10 seconds rolling back transactions and ensuring nobody else can connect regardless of privileges.
ALTER DATABASE 'dbname' SET SINGLE_USER WITH ROLLBACK AFTER 10 SECONDS;
Setting Database to Multi User Mode
ALTER DATABASE 'dbname' SET MULTI_USER
Setting Database to Emergency Mode
Used if data cannot be accessed in suspect database, will be accessible read only by sysadmin
ALTER DATABASE 'dbname' SET EMERGENCY;
Setting Database to Online
ALTER DATABASE 'dbname' SET ONLINE;
Setting Database to Readonly
Useful for taking a final backup
ALTER DATABASE 'dbname' SET READ_ONLY WITH NO_WAIT;
Setting Database to Read Write
ALTER DATABASE 'dbname' SET READ_WRITE;
RESTRICTED_USER allows for only members of the db_owner fixed database role and dbcreator and sysadmin fixed server roles to connect to the database, but does not limit their number. All connections to the database are disconnected in the timeframe specified by the termination clause of the ALTER DATABASE statement. After the database has transitioned to the RESTRICTED_USER state, connection attempts by unqualified users are refused.
Syntax is as follows:
alter database dbname
set RESTRICTED_USER
Link available on - http://blog.sanketik.com/index.php/how-to-restrict-user-to-access-database-in-ms-sql/
More detailed information is available at - http://www.blackwasp.co.uk/SQLRestrictedUser.aspx
Setting Database to Single User Mode
Keep query window open after running this. This will kick users off db after 10 seconds rolling back transactions and ensuring nobody else can connect regardless of privileges.
ALTER DATABASE 'dbname' SET SINGLE_USER WITH ROLLBACK AFTER 10 SECONDS;
Setting Database to Multi User Mode
ALTER DATABASE 'dbname' SET MULTI_USER
Setting Database to Emergency Mode
Used if data cannot be accessed in suspect database, will be accessible read only by sysadmin
ALTER DATABASE 'dbname' SET EMERGENCY;
Setting Database to Online
ALTER DATABASE 'dbname' SET ONLINE;
Setting Database to Readonly
Useful for taking a final backup
ALTER DATABASE 'dbname' SET READ_ONLY WITH NO_WAIT;
Setting Database to Read Write
ALTER DATABASE 'dbname' SET READ_WRITE;
Comments