Basically I\'ve followed a tutorial and decided to delete the .mdf
file afterwards.
Now whenever I try to run the application I get the following error
I didn't read all the responses, but if your .mdf
file is NOT part of the SQL installation path, like C:\Temp
, then the SQL Database Engine service account(s) will not have permission to create and write to the .ldf
file or even read the .mdf
file.
The solution is you have to give file system permissions to the SQL Server database engine service account that runs the SQL instance service. So for me, I gave permissions full control via Windows Explorer to my C:\Temp
path that contained my .mdf
file for the NT Service\MSSQL$SQLEXPRESS01
and NT Service\MSSQL$MSSQL2016
accounts.
Here is a Microsoft article that details this very issue.