I just installed SQL Server 2012 Express, and I'm running a C# program which attempts to create a database at a specified location using the following command:
create database [MyDatabase]
on primary (name=N'MyDatabase.mdf',
filename=N'C:\Users\myName\Documents\MyDatabase.mdf')
log on (name=N'MyDatabase_log.ldf',
filename=N'C:\Users\myName\Documents\MyDatabase_log.ldf')
This fails, both from the program and from management studio with the following error:
Msg 5133, Level 16, State 1, Line 2
Directory lookup for the file "C:\Users\mikea_000\Documents\MyDatabase.mdf" failed with the operating system error 5(Access is denied.).
Msg 1802, Level 16, State 1, Line 2
CREATE DATABASE failed. Some file names listed could not be created. Check related errors.
What steps to I need to give SQL Server permission to access this directory? I am connecting via integrated security (Windows Authentication in SSMS), and my user account is an administrator on my machine.
I can create and drop databases without specifying a file name with no issue:
CREATE DATABASE foo