microsoft sql server error 5123 attach database - how to fix
TRANSCRIPT
Fix SQL Server Error 5123
“CREATE FILE Encounter Operating System Error 5 (Access is denied).”
Table of ContentsWhat is the Error 5123Reasons of the Error 5123How to Attach a Database
Attaching Database Using T-SQLUsing sp_attach_db Stored Procedure
Methods to Fix the error 5123.ConclusionMore Resources
What is the Error 5123?The error 5123 is a type of permission error in SQL Server database. The error 5123 occurs when you want to attach the database which are situated at different locations.
Screenshot of the prompted error 5123
Reasons of the Error 5123
Attaching & detaching the with different logins.
Currently running process has no proper permission to run the program folder.
How to Attach a Database
There are two methods to attach the database in SQL Server. Methods are as follows:
1. Attaching database Using T-SQL
2. Using sp_attach_db stored procedure
Attaching Database Using T-SQL
CREATE DATABASE database_name ON (NAME = logical_file_name,FILENAME = 'os_file_name' ) [ ,..n ] AS SNAPSHOT OF source_database_name[;]
Using sp_attach_db Stored Procedure
Using stored procedure, we can attach the databases in the SQL Server. Given below is syntax for attaching a database:
sp_attach_db [ @dbname= ] 'dbname’ , [ @filename1= ] 'filename_n' [ ,...16 ]
Resolving the Issue 5123
You need to follow the given steps to fix the issue attach database failure in SQL Server:
1. Go to the .mdf file which you want to attach and right click on them.
2. Select the properties check the permissions of file.
3. Click on the add button to grant the login permission and give the full login control to the mdf file and its associated ndf file also.
4. Now you can attach the file. It should work.
Continue
“You can try run as administrator rather than giving permission to everyone.”
Conclusion
In this knowledge based tutorial I have shown that how can we attach the mdf / ldf files. If the attachment fails then what steps need to perform to overcome from this issue.
More Resources
To know more about attach database error: 5123 in MS SQL Server you should go through this one.
http://sqltechtips.blogspot.in/2015/12/fix-attach-database-error-5123.html