我看到了像这样的其他几个问题,但没有人能解决我的问题。
我有一个 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 mydatabase,select * 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 结果是列UserName和UserSID空,而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在脚本连接字符串中的部分是否错误?我该如何解决这个问题?
