There could be several reasons that you are facing this error.
You could try following solutions:
Although your user account is a member of Administrators group, the UAC in Windows 7 doesn't allow you to do administrator things unless you run programs "as administrator".
In this case you could do two things:
Run SQL Server Management Studio as an Administrator
You can also disable UAC. Go to the Control Panel -> User Accounts -> Change User Account Control Settings-> Set to "Never notify"
To fix, do the following:
Add the Administrators Group to the file security permissions with full control for the Data file and the Log File and then attach the database
Also check that mdf and ldf files are not blocked. Right click the
.bakfile > Properties > Unblock -> Apply)
.bakfile to default SQL backup location which has all the necessary permissions. You do not need to fiddle with anything else. In SQL SERVER 2012, this location is
C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\Backup
- Place the
C:\Program Files\Microsoft SQL Server\MSSQL11.SQLEXPRESS\MSSQL\DATA
- Right click on 'Databases' in the object explorer and select 'Attach'
- In the Attach Databases dialog box, Click on 'Add' button in the databases to attach:
- Navigate to the
C:\Program Files\Microsoft SQL Server\MSSQL11.SQLEXPRESS\MSSQL\DATA\Data.mdfand click Ok. To Add the
.ldffile you can do two things:
- Select the existing
- Delete the existing
.ldffile, as the SQL server will create one later once the database is attached
- Now the database 'Data' is created in SQL Sever