I have a database file .mdf
from MS SQL EXPRESS in folder:
C:\\Program Files\\Microsoft SQL Server\\MSSQL10.SQLEXPRESS\\MSSQL\\DATA
I just decided to create the file in D: instead of C: and everything worked well. windows 7...10 have many issues regarding the sharing and authorization of files and folder..
I had this issue on Windows 2003 with SQL 2005. I had to take ownership of the files as my Windows user account and I got the database to attache that way.
You have to right click on the file, select Properties, click OK to get past the information screen, click the Advanced button, select your account from the listing of available accounts or groups, apply that change, and Click OK on the Properties screen. Once you have done all that you will be able to manage the file permissions.
I logged into SSMS with Windows Authentication and I was able to attach the database without error.
Cheers!
Right Click on File mdf and ldf properties -> security ->full permission
The key is "operating system error 5". Microsoft helpfully list the various error codes and values on their site
https://msdn.microsoft.com/en-us/library/windows/desktop/ms681382(v=vs.85).aspx
ERROR_ACCESS_DENIED 5 (0x5) Access is denied.
1.copy your --.MDF,--.LDF files to pate this location For 2008 server C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA 2.In sql server 2008 use ATTACH and select same location for add
It's a Windows permissions issue. If you connected to your server using Windows Authentication then that Windows user needs permissions to the file. If you connected to your server using SQL Server authentication then the SQL Server instance account (MSSQL$, e.g. MSSQL$SQLEXPRESS) needs permissions to the file. The other solutions suggesting logging in as an administrator essentially accomplish the same thing (with a bit of a sledgehammer :).
If the database file is in your SQL Server's data folder then it should have inherited the user rights for the SQL Server account from that folder so the SQL Server authentication should have worked. I would recommend fixing the SQL Server instance's account's rights for that folder. If the data file is somewhere else and the SQL Server account does not have permissions then you will likely encounter other problems later. Again, the better solution is to fix the SS account rights. Unless you are always going to log in as administrator...