I want to create a database on my SQL Server Express in SQL Server Management Studio and when I execute the command I get this error:
Msg 5133, Level 16, State 1, Line 1
Directory lookup for the file "C:\Users\godorojaalexandru\WebApiFileTable\AspNetCoreFileUploadFileTable2\FTDB.mdf" failed with the operating system error 5(Access is denied.).Msg 1802, Level 16, State 1, Line 1
CREATE DATABASE failed. Some file names listed could not be created. Check related errors.
Here is the query I was instructed to create:
CREATE DATABASE AspNetCoreFileUploadFileTable2
ON PRIMARY
(Name = AspNetCoreFileUploadFileTable2,
FILENAME = 'C:\Users\godorojaalexandru\WebApiFileTable\AspNetCoreFileUploadFileTable2\FTDB.mdf'),
FILEGROUP FTFG CONTAINS FILESTREAM
(NAME = AspNetCoreFileUploadFileTableFS2,
FILENAME='C:\Users\godorojaalexandru\WebApiFileTable\AspNetCoreFileUploadFileTable2\FS')
LOG ON
(Name = AspNetCoreFileUploadFileTableLog2,
FILENAME = 'C:\Users\godorojaalexandru\WebApiFileTable\AspNetCoreFileUploadFileTable2\FTDBLog.ldf')
WITH FILESTREAM (NON_TRANSACTED_ACCESS = FULL,
DIRECTORY_NAME = N'AspNetCoreFileUploadFileTable2');
GO
I went to the directory's properties and observed that the access was set to full-access for both the server and the system, so I don't understand why it says that the access is denied.
I am following a tutorial and it just said to run the command above after creating the directory (WebApiFileTable
). Do I have to create the files themselves (FTDB.mdf
, FS, FTDBLog.ldf
) before running this command, and if so, how do I do it?
Thank you kindly.
Error 5 sure is an Access Denied.
The issue is likely to be with the permissions that the SQL Server service account has to that folder. (Or there is already a file there that it can't delete).
Check SQL Server Configuration Manager to see who SQL Server is logging in as.
And make sure that login user has permissions to the whole filesystem paths that you're using.
To check if it's really just a permissions error, perhaps try a C:\temp folder for everything first (after making sure the service account has permissions to that).