这段代码有什么问题?

时间:2015-02-11 16:19:10

标签: sql ssms

我是SSMS的新手,我正在尝试执行此代码:

use master
create database SQL20145Db2
on primary
( name = Sql2015Data2, filename='C:\Program Files (x86)\Microsoft SQL Server\MSSQL.1\MSSQL\Data\Sql2015Data2',
size=4MB, MaxSize=15, FileGrowth= 20%
)
log on
(Name=Sql2015Log2, filename='C:\Program Files (x86)\Microsoft SQL Server\MSSQL.1\MSSQL\Data\Sql2015Log2',
size= 1MB,MaxSize=5Mb,filegrowth=1MB
)

但是消息窗格显示以下错误:

Msg 5123, Level 16, State 1, Line 2
CREATE FILE encountered operating system error 5(failed to retrieve text for this error. Reason: 15105) while attempting to open or create the physical file 'C:\Program Files (x86)\Microsoft SQL Server\MSSQL.1\MSSQL\Data\Sql2015Data2'.
Msg 1802, Level 16, State 4, Line 2
CREATE DATABASE failed. Some file names listed could not be created. Check related errors.

1 个答案:

答案 0 :(得分:0)

发生此错误的原因是注册表值DefaultDataDefaultLog(对应于默认数据目录)为空或不存在。

有关详细信息,请参阅documentation

大多数情况下,这些注册表值不存在,因为它们实际上需要作为Admin访问。因此,要解决此问题,只需运行您用于以管理员身份执行sql的任何应用程序。