I have a database file .mdf
from MS SQL EXPRESS in folder:
C:\\Program Files\\Microsoft SQL Server\\MSSQL10.SQLEXPRESS\\MSSQL\\DATA
In my case I have got the error when trying to create a databae on a new drive. To overcome the problem I created a new folder in that drive and set the user properties Security to full control on it(It may be sufficient to set Modify ). Conclusion: SET the Drive/Folder Properties Security for users to "Modify".
Opening SSMS as Administrator and running as SQL Auth vs Windows Auth did not work.
What worked was to just change my filename to the same location where the LDF and MDF files are located.
alter database MyDB
add file ( name = N'FileStreamName',
filename = N'D:\SQL Databases\FileStreamSpace' )
to filegroup DocumentFiles;
Here are the steps:
This same problem occurs when the owners of the file have been deleted. When this happens, if you go to the file's properties, you will see a SID rather than a user name. Take ownership of the file (giving yourself FULL CONTROL). Once that is done you can do whatever you need to do with the file.
I've had this work when logging in as the administrator didn't do the trick.
if you have mount points add the the SQL server service account to volume security accordingly
Start->Run->services.msc
->scroll through the list of services until you find SQL Server->right-click->properties->Log On tab:
Then choose Local System Account
and check the Allow service to interact with desktop
checkbox.
Restart the service.