Disable users of a database not Logins in SQL server 2008

Anandita Sharma picture Anandita Sharma · Feb 10, 2015 · Viewed 20.9k times · Source

To disable users of a Database in SQL Server 2008, I gave the command:

Use Database
Go
Revoke Connect from username;

It works for the users with SQL Server Authentication such as abcdef.

But not for the user with Windows Authentication such as DomainName\abcdef. It gives the error:

Msg 102, Level 15, State 1, Line 1 Incorrect syntax near '\'.

It does not even work by using the single quotes around the username in the above mentioned command.

Please suggest.

Answer

Anandita Sharma picture Anandita Sharma · Feb 10, 2015

It worked when I used the double quotes around the username such as:

USE Database
GO
REVOKE CONNECT FROM "domain\user"

To enable users of a database:

USE Database
GO
GRANT CONNECT TO "username"

To disable Logins of a server:

USE master
GO
ALTER LOGIN loginname DISABLE;

To enable Logins of a server:

USE master
GO
ALTER LOGIN loginname ENABLE;