0

I'm new in SSMS, and I'm trying to execute this code:

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
)

But the messages pane displays this error:

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.
  • Possible duplicate: http://stackoverflow.com/questions/11178536/create-file-encountered-operating-system-error-5failed-to-retrieve-text-for-thi – Andrew Carmichael Feb 11 '15 at 16:24

1 Answers1

0

This error happen because the registry value DefaultData and DefaultLog (which correspond to default data directory) are either empty or does not exists.

See documentation for more information.

Most of the time, these registry values does not exists because they actually need to be accessed as Admin. So, to fix this issue, simply run whatever application you are using to execute the sql as an administrator.

Jean-François Savard
  • 20,626
  • 7
  • 49
  • 76
  • I do run SSMS as admin, and the problem has not been fixed! –  Feb 11 '15 at 16:57
  • @MohammedElshawaf you are getting a permission error, you must make sure that the user have all right for `C:\Program Files (x86)\Microsoft SQL Server\MSSQL.1\MSSQL\Data\Sql2015Log2` – Jean-François Savard Feb 11 '15 at 17:16