sql-server - 如何授予 MSSQL$SQL2016 写入文件夹的权限

标签 sql-server permissions windows-10-desktop

早晨,

我撞到了一堵砖墙,我需要指出正确的方向。
我想要做的是授予我的 SQL Server 实例权限,以便在我安装在本地计算机上的新硬盘驱动器上的目录中创建 MDB/LDB 文件,而不使用每个人。

当我尝试在文件夹中创建新数据库(通过管理工作室)时,出现以下错误:

===================================

Create failed for Database 'TestDatabase1'.  (Microsoft.SqlServer.Smo)

------------------------------
For help, click: http://go.microsoft.com /fwlink?ProdName=Microsoft+SQL+Server&ProdVer=13.0.16106.4+((SSMS_Rel_16_5).170125-2137)&EvtSrc=Microsoft.SqlServer.Management.Smo.ExceptionTemplates.FailedOperationExceptionText&EvtID=Create+Database&LinkId=20476

------------------------------
Program Location:

   at Microsoft.SqlServer.Management.Smo.SqlSmoObject.CreateImpl()
   at Microsoft.SqlServer.Management.SqlManagerUI.CreateDatabaseData.DatabasePrototype.ApplyChanges(Control marshallingControl)
   at Microsoft.SqlServer.Management.SqlManagerUI.CreateDatabase.DoPreProcessExecution(RunType runType, ExecutionMode& executionResult)
   at Microsoft.SqlServer.Management.SqlMgmt.SqlMgmtTreeViewControl.DoPreProcessExecutionAndRunViews(RunType runType)
   at Microsoft.SqlServer.Management.SqlMgmt.SqlMgmtTreeViewControl.ExecuteForSql(PreProcessExecutionInfo executionInfo, ExecutionMode& executionResult)
   at Microsoft.SqlServer.Management.SqlMgmt.SqlMgmtTreeViewControl.Microsoft.SqlServer.Management.SqlMgmt.IExecutionAwareSqlControlCollection.PreProcessExecution(PreProcessExecutionInfo executionInfo, ExecutionMode& executionResult)
   at Microsoft.SqlServer.Management.SqlMgmt.ViewSwitcherControlsManager.RunNow(RunType runType, Object sender)

===================================

An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo)

------------------------------
Program Location:

   at Microsoft.SqlServer.Management.Common.ServerConnection.ExecuteNonQuery(String sqlCommand, ExecutionTypes executionType, Boolean retry)
   at Microsoft.SqlServer.Management.Common.ServerConnection.ExecuteNonQuery(StringCollection sqlCommands, ExecutionTypes executionType, Boolean retry)
   at Microsoft.SqlServer.Management.Smo.ExecutionManager.ExecuteNonQuery(StringCollection queries, Boolean retry)
   at Microsoft.SqlServer.Management.Smo.SqlSmoObject.ExecuteNonQuery(StringCollection queries, Boolean includeDbContext, Boolean executeForAlter)
   at Microsoft.SqlServer.Management.Smo.SqlSmoObject.CreateImplFinish(StringCollection createQuery, ScriptingPreferences sp)
   at Microsoft.SqlServer.Management.Smo.SqlSmoObject.CreateImpl()

===================================

CREATE FILE encountered operating system error 5(Access is denied.) while attempting to open or create the physical file 'D:\MSSQL\Data\TestDatabase1.mdf'.
CREATE DATABASE failed. Some file names listed could not be created. Check related errors. (.Net SqlClient Data Provider)

------------------------------
For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft%20SQL%20Server&ProdVer=13.00.4224&EvtSrc=MSSQLServer&EvtID=5123&LinkId=20476

------------------------------
Server Name: my_machine\SQL2016
Error Number: 5123
Severity: 16
State: 1
Line Number: 1


------------------------------
Program Location:

   at Microsoft.SqlServer.Management.Common.ConnectionManager.ExecuteTSql(ExecuteTSqlAction action, Object execObject, DataSet fillDataSet, Boolean catchException)
   at Microsoft.SqlServer.Management.Common.ServerConnection.ExecuteNonQuery(String sqlCommand, ExecutionTypes executionType, Boolean retry)

SQL Server 实例正在使用“NT Service\MSSQL$2016”登录。
我检查了原始数据文件夹,MSSQL$2016 有读写权限。

我看过这些帖子:

https://blog.sqlauthority.com/2018/08/25/sql-server-fix-create-file-encountered-operating-system-error-5-access-is-denied/

https://docs.microsoft.com/en-us/sql/database-engine/configure-windows/configure-file-system-permissions-for-database-engine-access?view=sql-server-2017

https://serverfault.com/questions/507496/sql-server-2012-with-account-nt-service-mssqlserver-access-is-denied-in-domain

http://documentation.sqlserverbooster.com/en/1_1_2/SQLServerBoosterDocumentation.html?AddingreadwritepermissionstoNTSe.html

https://dba.stackexchange.com/questions/70069/how-do-i-give-file-system-access-to-sql-servers-sqlserveragent-virtual-account

我还尝试通过右键单击文件夹-> 属性-> 安全性将以下内容添加到文件夹中,但没有一个起作用
NT Service\MSSQL$SQL2016
[NT Service\MSSQL$SQL2016]
[NT Service]\MSSQL$SQL2016
[NT Service]\[MSSQL$SQL2016]
MSSQL$SQL2016

当我单击“检查名称”时,它找不到它。

如果它有任何区别,这是在域上的 Windows 10 PC 上。

我错过了一些明显的东西,但我不确定它是什么。如果您能指点我一份文件,我将不胜感激。

最佳答案

在我的机器上,解决方案是分配用户:NT Service\MSSQL$MSSQLSERVER2016 (而不是 MSSQL$MSSQLSERVER2016 )
在您管理对具体目录的访问权限的对话框中。

关于sql-server - 如何授予 MSSQL$SQL2016 写入文件夹的权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55220870/

相关文章:

sql server if block errors when running a stored proc inside - 给出语法错误

SQL Server : Retrieve the duplicate value in a column

php - 同时更新同一台服务器上的数百个站点

azure - 为什么当我通过 Powershell 将 Api 权限上传到 AzureAd 时,我只得到 Id?

MySQL数据库权限问题

php - 使用 PDO 的 odbc 通过 Windows 身份验证连接到 MSSQL 服务器实例

c# - Entity Framework : SqlGeography vs DbGeography

c# - 无法从 UWP 打包项目 (UWP + Win32) 构建 ARM64

cmd - Windows 10 中的复制粘贴在命令提示符下不起作用,右键单击或键盘快捷键也不起作用