禁用数据库用户而不是SQL Server 2008中的登录

时间:2022-02-26 09:35:34

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

要禁用SQL Server 2008中的数据库用户,我给出了以下命令:

Use Database
Go
Revoke Connect from username;

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

它适用于具有SQL Server身份验证的用户,例如abcdef。

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

但不适用于具有Windows身份验证的用户,例如DomainName \ abcdef。它给出了错误:

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

消息102,级别15,状态1,行1'''附近的语法不正确。

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

它甚至不能通过在上面提到的命令中使用用户名周围的单引号来工作。

Please suggest.

请建议。

2 个解决方案

#1


2  

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

当我在用户名周围使用双引号时,它可以工作,例如:

use Database
Go
Revoke Connect from "DomainName\abcdef"

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;

#2


0  

I identify the disabled users by using the sys.sysusers DMV

我使用sys.sysusers DMV识别已禁用的用户

you can see on the example below. the result of the query, and further below, navigating through ssms.

你可以在下面的例子中看到。查询的结果,以及下面的,导航ssms。

select * from sys.sysusers 
where islogin =1
  and hasdbaccess = 0

禁用数据库用户而不是SQL Server 2008中的登录

禁用数据库用户而不是SQL Server 2008中的登录

#1


2  

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

当我在用户名周围使用双引号时,它可以工作,例如:

use Database
Go
Revoke Connect from "DomainName\abcdef"

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;

#2


0  

I identify the disabled users by using the sys.sysusers DMV

我使用sys.sysusers DMV识别已禁用的用户

you can see on the example below. the result of the query, and further below, navigating through ssms.

你可以在下面的例子中看到。查询的结果,以及下面的,导航ssms。

select * from sys.sysusers 
where islogin =1
  and hasdbaccess = 0

禁用数据库用户而不是SQL Server 2008中的登录

禁用数据库用户而不是SQL Server 2008中的登录