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文档,截取部分如下所示
使用 Windows 资源管理器,导航到存储数据库文件的文件系统位置。右键单击文件系统文件夹,然后单击“属性”。
在“安全性”选项卡上,单击“编辑”,然后单击“添加”。
在“选择用户、计算机、服务帐户或组”对话框中,单击“位置”,在位置列表的顶部选择您的计算机名称,然后单击“确定”。
在“输入要选择的对象名称”框中,键入联机丛书主题“配置 Windows 服务帐户和权限”中所列的每个服务 SID 的名称。 (对于数据库引擎每个服务 SID,将 NT SERVICE\MSSQLSERVER 用于默认实例,或将 NT SERVICE\MSSQL$InstanceName 用于命名实例。)
单击“检查名称”以验证该条目。验证经常失败,而且可能告知您找不到该名称。单击“确定”时,将显示“找到多个名称”对话框。
现在选择每个服务 SID(MSSQLSERVER 或 NT SERVICE\MSSQL$InstanceName),然后单击“确定”。
再次单击“确定”以返回“权限”对话框。
在“组或用户”名称框中,选择每个服务 SID,然后在“<名称> 的权限”框中,为“完全控制”选中“允许”复选框。
单击“应用”,然后单击“确定”两次以退出。
具体操作过程的截图如下所示
权限的话,至少需要”Read & Execute“、”List Folder Content“、”Read“、”Write“权限,当然如果你能给”Full Control“权限那肯定是可以。权限我们应该尽量控制最小范围内。
此时就能解决这个错误,此时你删除该用户,然后在这个目录添加EVERYONE用户,授予上面的权限也能解决这个错误。当然在安全性上就不如给虚拟账户NT Service\MSSQLSERVER账号授权。
肯定有细心的人会问,我们不添加虚拟账户NT Service\MSSQLSERVER或EVERYONE,我们重新添加这个用户GETTESTNT55\Users、授予同样的权限是否可以解决这个问题? 答案是依然会遇到这个错误,为什么呢? 暂时我没有搞明白具体原因,是不是有点讽刺,知道了怎么解决,但是依然不清楚具体原因。当然涉及权限的问题确实有点复杂。如果哪位知道具体原因,请不吝赐教。
----------------------------------------------分割线 2015-12-15补充--------------------------------------------------
今天有空,为了搞清楚这个问题,我查了大量的资料。下面是一些来自MSDN的资料和我的一些验证。下面我们一一梳理清楚。
关于SQL SERVER服务的一些属性与配置的信息(中文与英文信息)。
用于启动和运行 SQL Server 的启动帐户可以是域用户帐户、本地用户帐户、托管服务帐户、虚拟帐户或内置系统帐户。 若要启动和运行 SQL Server 中的每项服务,这些服务都必须有一个在安装过程中配置的启动帐户。
此部分介绍可配置为启动 SQL Server 服务的帐户、SQL Server 安装程序使用的默认值、Per-service SID 的概念、启动选项以及配置防火墙。
Service Properties and Configuration
Startup accounts used to start and run SQL Server can be domain user accounts, local user accounts, managed service accounts, virtual accounts, or built-in system accounts. To start and run, each service in SQL Server must have a startup account configured during installation.
This section describes the accounts that can be configured to start SQL Server services, the default values used by SQL Server Setup, the concept of per-service SID’s, the startup options, and configuring the firewall.
NT Service\MSSQLSERVER 它属于虚拟账户(Virtual Account)。虚拟账户的概念请看下面MSDN描述(中文与英文)
虚拟帐户
Windows Server 2008 R2 和 Windows 7 中的虚拟帐户是“托管的本地帐户”,此类帐户提供以下功能以简化服务管理。 虚拟帐户是自动管理的,并且虚拟帐户可以访问域环境中的网络。 如果在 Windows Server 2008 R2 或 Windows 7 上安装 SQL Server 时对服务帐户使用默认值,则将使用将实例名称用作服务名称的虚拟帐户,格式为 NT SERVICE\<SERVICENAME>。 以虚拟帐户身份运行的服务通过使用计算机帐户的凭据(格式为 <domain_name>\<computer_name>$)访问网络资源。 当指定一个虚拟帐户以启动 SQL Server 时,应将密码留空。 如果虚拟帐户无法注册服务主体名称 (SPN),则手动注册该 SPN。 有关手动注册 SPN 的详细信息,请参阅手动注册 SPN。
Virtual Accounts
Virtual accounts in Windows Server 2008 R2 and Windows 7 are managed local accounts that provide the following features to simplify service administration. The virtual account is auto-managed, and the virtual account can access the network in a domain environment. If the default value is used for the service accounts during SQL Server setup on Windows Server 2008 R2 or Windows 7, a virtual account using the instance name as the service name is used, in the format NT SERVICE\<SERVICENAME>. Services that run as virtual accounts access network resources by using the credentials of the computer account in the format <domain_name>\<computer_name>$. When specifying a virtual account to start SQL Server, leave the password blank. If the virtual account fails to register the Service Principal Name (SPN), register the SPN manually. For more information on registering a SPN manually, see Manual SPN Registration.
关于Users组的概念
A built-in group. After the initial installation of the operating system, the only member is the Authenticated Users group. When a computer joins a domain, the Domain Users group is added to the Users group on the computer. Users can perform tasks such as running applications, using local and network printers, shutting down the computer, and locking the computer. Users can install applications that only they are allowed to use if the installation program of the application supports per-user installation.
那么我们用Icacls命令来查看E:\SQL_DATA目录的随机访问控制列表 (DACL),我们可以对比GETTESTNT55\Users删除前后的权限,发现删除该用户组后,BUILTIN\Users对该目录的权限没有了。
看来SQL SERVER服务访问相关的文件系统权限的最终映射到了这个“内置帐户”账户上了(仅仅个人猜想、判断)。所以才会出现我上面的错误。
在文件上面我曾经介绍过“我们不添加虚拟账户NT Service\MSSQLSERVER,我们重新添加这个用户、授予同样的权限是否可以解决这个问题? 答案是依然会遇到这个错误,为什么呢?” ,当时我是在E:\SQL_DATA目录设置权限。这样依然不行,如果我去E盘设置权限则不会出现这个错误(实验验证结果)。我对比了下两者在E:\SQL_DATA文件上的随机访问控制列表 (DACL)的不同。如下所示。权限的顺序有所不同(真是脑壳痛,研究到此为止),看来是某种权限控制机制导致。
参考资料:
http://www.guyellisrocks.com/2010/07/create-file-encountered-operating.html
https://msdn.microsoft.com/zh-cn/library/jj219062.aspx
http://ss64.com/nt/syntax-security_groups.html
https://msdn.microsoft.com/zh-cn/library/ms143504(v=sql.120).aspx#VA_Desc
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盘下的某一个目录下面. ALTER DATABASE ...
- mysql数据库报错:InnoDB: Operating system error number 13 in a file operation
环境:centos6.5 x86_64 启动mysql发现日志报错(日志路径可以查看/etc/my.cnf的配置) 160722 10:34:08 [Note] Found 42570716 of 4 ...
- 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] Plugi ...
- DBCC CHECKDB 遭遇Operating system error 112(failed to retrieve text for this error. Reason: 15105) encountered
我们一个SQL Server服务器在执行YourSQLDBa的作业YourSQLDba_FullBackups_And_Maintenance时遇到了错误: Exec YourSQLDba.Maint ...
- LogWriter: Operating system error 21(error not found) encountered
一台老旧的数据库服务器(SQL Server 2005)突然报如下错误,而且数据库处于RECOVERY PENDING ,检查错误日志,发现这个错误是突然出现的.没有任何其它人为误操作导致 Dat ...
- Operating system error 32(failed to retrieve text for this error. Reason: 15105)
一台数据库服务器的事务日志备份作业偶尔会出现几次备份失败的情况,具体的错误信息为: DATE/TIME: 2018/7/30 12:10:52 DESCRIPTION: BackupDiskFi ...
- Error: 17053 LogWriter: Operating system error 21(The device is not ready.)
今天在Detach数据库的时候出现错误,运行DBCC CHECKDB从SQL Server error log中看到下面的信息: Error: 17053, Severity: 16, State: ...
- 如何定位“Operating system error 32(failed to retrieve text for this error. Reason: 15105)”错误中被占用的文件
之前在这篇"Operating system error 32(failed to retrieve text for this error. Reason: 15105)"博 ...
- Parser Error Message: Access is denied【转】
PRB: Access Denied Error When You Make Code Modifications with Index Services Running View products ...
随机推荐
- [ES] 基础概念
Elasticsearch是基于Luence实现的一款搜索引擎,支持分布式和集群,并且搜索近实时,主要用于搜索和数据分析 索引 index 可以理解为数据库中的database,存储的是实际数据,因为 ...
- Javascript的无new构建
看jquery源代码第一步的时候,对于jquery对象的创建就看的云里雾里,琢磨半天终于有点感觉了,在此记录下 第一种方式: var A = function(){ return A.prototyp ...
- 遍历迭代map的集中方法
public static void main(String[] args) { Map<String, String> map = new HashMap<String, Stri ...
- Gobblin采集kafka数据
作者:Syn良子 出处:http://www.cnblogs.com/cssdongl 转载请注明出处 找时间记录一下利用Gobblin采集kafka数据的过程,话不多说,进入正题 一.Gobblin ...
- 【十大经典数据挖掘算法】C4.5
[十大经典数据挖掘算法]系列 C4.5 K-Means SVM Apriori EM PageRank AdaBoost kNN Naïve Bayes CART 1. 决策树模型与学习 决策树(de ...
- jQuery-1.9.1源码分析系列(十六)ajax——响应数据处理和api整理
ajax在得到请求响应后主要会做两个处理:获取响应数据和使用类型转化器转化数据 a.获取响应数据 获取响应数据是调用ajaxHandleResponses函数来处理. ajaxHandleRespon ...
- IIS与ASP.NET管道
IIS 5.x与ASP.NET 我们先来看看IIS 5.x是如何处理基于ASP.NET资源(比如.aspx,.asmx等)请求的,整个过程基本上可以通过图1体现. IIS 5.x运行在进程InetIn ...
- 在ASP.NET Core中怎么使用HttpContext.Current
一.前言 我们都知道,ASP.NET Core作为最新的框架,在MVC5和ASP.NET WebForm的基础上做了大量的重构.如果我们想使用以前版本中的HttpContext.Current的话,目 ...
- System.Security.Cryptography.CryptographicException,密钥集不存在
非常感谢,已经解决了.是当前用户没有权限访问证书的私钥文件的问题,之前尝试去解决,但是在对:C:\Documents and Settings\All Users\Application Data\M ...
- Castle.ActiveRecord多数据库配置
最近使用Castle.ActiveRecord框架,网上关于多数据支持的文章很少,因此有了这篇博文的产生. 开发工具VS2015,Sql Server2008R2 新建数据库,数据初始化脚本如下: - ...









