3

我看到了像这样的其他几个问题,但没有人能解决我的问题。

我有一个 SQL 2016 Express 和一个数据库mydatabase。我使用创建了一个登录名,Windows Authentication并使用了我的 AD 用户domain\myuser。在mydatabase-> 安全 -> 用户中,我创建了一个名为myuser(用户类型 = Windows 用户,登录名 = domain\myuser)的用户。默认架构是 dbo,我在 Securables 菜单中添加mytable并赋予了以下权限:Alter、Delete、Insert、Select 和 Update。

如果我以 身份打开 SQL Management Studio domain\myuser,连接到该 SQL 服务器,然后运行use mydatabaseselect * from mytable一切正常。

现在,使用 vbscript,从运行 as 的命令提示符domain\myuser,它将失败。myscript.vbs脚本的相关部分是这样的:

strConn = "PROVIDER=SQLOLEDB;Server=myserver\myinstance;Integrated Security=SSPI;"
Set cxn = Wscript.CreateObject("ADODB.Connection")
cxn.Open strConn
cxn.CommandTimeout = 0 
strSqlQuery = "use mydatabase"
Set rs=cxn.Execute(strSqlQuery)

这将失败:

myscript.vbs(6, 1) Microsoft OLE DB Provider for SQL Server:
The server principal "domain\myuser" is not able to access the
database "mydatabase" under the current security context.

我尝试database=mydatabase在 SQL 连接字符串中添加,但它也不起作用。

看了其他问题的一些答案,有人要求在SQL Management Studio中运行如下命令:

sp_change_users_login  @Action='Report';

不清楚是 db_owner 还是受影响的用户,所以我同时运行了这两个。使用 db_owner 结果是列UserNameUserSID空,而domain\myuser它说:

Msg 15247, Level 16, State 1, Procedure sp_change_users_login, Line 51 [Batch Start Line 10]
User does not have permission to perform this action.

Integrated Security在脚本连接字符串中的部分是否错误?我该如何解决这个问题?

4

2 回答 2

1

对于我的情况,当我深入研究时,我发现用户在 SQL Server 和 MSDB 上拥有超级权限,并且工作正常。

就我而言,原因是: PUBLIC 角色拒绝了 CONNECT 权限。

2 种可能的解决方案: 1. 分别为所有用户提供连接权限 2. 为 PUBLIC 角色提供连接权限

于 2018-11-14T04:33:50.797 回答
0

您需要在数据库级别设置权限。为此,请按照以下步骤操作:

  1. 右键单击所需的数据库 (MyDB)
  2. 从弹出菜单中选择“属性”
  3. 从左侧菜单中选择“权限”
  4. 仅检查所需的权限

在此处输入图像描述

于 2020-09-23T19:14:16.437 回答