CREATE FILE encountered operating system error 5(Access is denied.)

这篇博文主要演示”CREATE FILE encountered operating system error 5(Access is denied.)“错误如出现的原因(当然只是导致这个错误出现的一种场景而已)和如何解决这个问题以及一些不解的迷惑。

实验环境:

操作系统版本: Windows Server 2012 SP2

数据库的版本:Microsoft SQL Server 2014 - 12.0.2000.8

如下所示,SQL Server Database Services 服务的启动账号为NT Service\MSSQLSERVER, 我们先设置一下数据库的默认路径为E:\SQL_DATA

此时查看E:\SQL_DATA 目录的权限(被屏蔽的是一域账号)。此时我们创建数据库Test完全没有问题。我们先删除数据库Test。

现在我们删除用户GETTESTNT55\Users这个账号,在目录E:\SQL_DATA的属性(Properties)->安全(Security)-> 编辑(Edit)下直接删除会遇到下面错误。

我们从E盘的根目录,右键属性选择Security 删除这个用户,然后我创建新的数据库时就会遇到CREATE FILE encountered operating system error 5(Access is denied.)错误。

那么如何解决呢? 我们可以给当前目录添加虚拟帐户NT Service\MSSQLSERVER 并授予相关权限解决这个问题。具体可以参考MSDN文档,截取部分如下所示

  1. 使用 Windows 资源管理器,导航到存储数据库文件的文件系统位置。右键单击文件系统文件夹,然后单击“属性”

  2. “安全性”选项卡上,单击“编辑”,然后单击“添加”
  3. “选择用户、计算机、服务帐户或组”对话框中,单击“位置”,在位置列表的顶部选择您的计算机名称,然后单击“确定”
  4. “输入要选择的对象名称”框中,键入联机丛书主题“配置 Windows 服务帐户和权限”中所列的每个服务 SID 的名称。 (对于数据库引擎每个服务 SID,将 NT SERVICE\MSSQLSERVER 用于默认实例,或将 NT SERVICE\MSSQL$InstanceName 用于命名实例。)
  5. 单击“检查名称”以验证该条目。验证经常失败,而且可能告知您找不到该名称。单击“确定”时,将显示“找到多个名称”对话框。
  6. 现在选择每个服务 SID(MSSQLSERVER 或 NT SERVICE\MSSQL$InstanceName),然后单击“确定”
  7. 再次单击“确定”以返回“权限”对话框。
  8. “组或用户”名称框中,选择每个服务 SID,然后在“<名称> 的权限”框中,为“完全控制”选中“允许”复选框。
  9. 单击“应用”,然后单击“确定”两次以退出。

具体操作过程的截图如下所示

权限的话,至少需要”Read & Execute“、”List Folder Content“、”Read“、”Write“权限,当然如果你能给”Full Control“权限那肯定是可以。权限我们应该尽量控制最小范围内。

此时就能解决这个错误,此时你删除该用户,然后在这个目录添加EVERYONE用户,授予上面的权限也能解决这个错误。当然在安全性上就不如给虚拟账户NT Service\MSSQLSERVER账号授权。

肯定有细心的人会问,我们不添加虚拟账户NT Service\MSSQLSERVER或EVERYONE,我们重新添加这个用户GETTESTNT55\Users、授予同样的权限是否可以解决这个问题? 答案是依然会遇到这个错误,为什么呢? 暂时我没有搞明白具体原因,是不是有点讽刺,知道了怎么解决,但是依然不清楚具体原因。当然涉及权限的问题确实有点复杂。如果哪位知道具体原因,请不吝赐教。

参考资料:

http://www.guyellisrocks.com/2010/07/create-file-encountered-operating.html

http://stackoverflow.com/questions/11178536/create-file-encountered-operating-system-error-5failed-to-retrieve-text-for-thi

https://msdn.microsoft.com/zh-cn/library/jj219062.aspx

时间: 2024-08-11 01:35:00

CREATE FILE encountered operating system error 5(Access is denied.)的相关文章

Unable to open the physical file xxxx. Operating system error 2

在新UAT服务器上,需要将tempdb放置在SSD(固态硬盘)上.由于SSD(固态硬盘)特性,所以tempdb的文件只能放置在D盘下面,而不能是D盘下的某一个目录下面. ALTERDATABASE tempdb MODIFY FILE(name='tempdev', filename='D:\tempdb.mdf') ;   GO ALTERDATABASE tempdb MODIFY FILE(name='templog', filename='D:\templog.ldf') ; GO 修改

InnoDB: Operating system error number 87 in a file operation. 错误87的解决方法

InnoDB: Operating system error number 87 in a file operation. 错误87的解决方法 140628  8:10:48 [Note] Plugin 'FEDERATED' is disabled.140628  8:10:48 InnoDB: The InnoDB memory heap is disabled140628  8:10:48 InnoDB: Mutexes and rw_locks use Windows interlock

Directory lookup for the file &quot;xxx.mdf&quot; failed with the operating system error 2

Directory lookup for the file "xxx.mdf" failed with the operating system error 2(系统找不到指定的文件.). reason: sql2005以后 禁用了xp_cmdshell存储过程 solution: sp_configure 'show advanced options', 1GORECONFIGUREGOsp_configure 'xp_cmdshell', 1GORECONFIGUREGO

Operating system error 995(The I/O operation has been aborted because of either a thread)

From https://technet.microsoft.com/en-us/library/aa337272.aspx MSSQLSERVER_3271 Other Versions Topic Status: Some information in this topic is preview and subject to change in future releases. Preview information describes new features or changes to

Parser Error Message: Access is denied【转】

PRB: Access Denied Error When You Make Code Modifications with Index Services Running View products that this article applies to. Article ID : 329065 Last Review : June 25, 2004 Revision : 3.0 This article was previously published under Q329065 SYMPT

[解决]Mercurial HTTP Error 500: Access is denied on&#160;00changelog.i

总之,用户对仓库目录要有写权限 00changelog, access is denied, hg, http error 500, mercurial, permissions, push Mercurial HTTP Error 500: Access is denied on 00changelog.i January 13, 2011 Today I created a new Mercurial repository on a Windows server.  I cloned it,

General-Purpose Operating System Protection Profile

1 Protection Profile Introduction ? This document defines the security functionality expected to be provided by a general-purpose operating system capable of operating in a networked environment. It also provides a set of assurance components that de

Single-stack real-time operating system for embedded systems

A real time operating system (RTOS) for embedded controllers having limited memory includes a continuations library, a wide range of macros that hide continuation point management, nested blocking functions, and a communications stack. The RTOS execu

ASP ACCESS 报错:Selected collating sequence not supported by the operating system.

Selected collating sequence not supported by the operating system. 这个问题是在一个国外服务器上放ASP+ACCESS程序时出现的问题. 在本地测试的时候都好好的.没有任何问题,但传上去之后,服务器就提示:Selected collating sequence not supported by the operating system. 这个问题是因为国外服务器的系统是英文系统.所以与中文的ACCESS数据库出了差错. 具体的解决