SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Attach DB fails


Attach DB fails

Author
Message
pietlinden
pietlinden
SSC Guru
SSC Guru (52K reputation)SSC Guru (52K reputation)SSC Guru (52K reputation)SSC Guru (52K reputation)SSC Guru (52K reputation)SSC Guru (52K reputation)SSC Guru (52K reputation)SSC Guru (52K reputation)

Group: General Forum Members
Points: 52022 Visits: 16664
I think I just did a dumb thing and didn't properly detach my databases before reinstalling SQL Server 2016. When I try to attach, it fails:
CREATE DATABASE Galactic2  
ON (FILENAME = 'C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\Galactic.mdf'),
(FILENAME = 'C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\Galactic._Log.ldf')
FOR ATTACH;


Error:
Msg 5120, Level 16, State 101, Line 3
Unable to open the physical file "C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\Galactic.mdf". Operating system error 2: "2(The system cannot find the file specified.)".
Msg 1802, Level 16, State 7, Line 3
CREATE DATABASE failed. Some file names listed could not be created. Check related errors.

I'm working on my laptop, and I'm the local admin. Still no joy. What am I doing wrong? Do I have to change the permissions on the individual MDF and LDF files?
Ed Wagner
Ed Wagner
SSC Guru
SSC Guru (260K reputation)SSC Guru (260K reputation)SSC Guru (260K reputation)SSC Guru (260K reputation)SSC Guru (260K reputation)SSC Guru (260K reputation)SSC Guru (260K reputation)SSC Guru (260K reputation)

Group: General Forum Members
Points: 260103 Visits: 12223
pietlinden - Sunday, February 4, 2018 5:39 PM
I think I just did a dumb thing and didn't properly detach my databases before reinstalling SQL Server 2016. When I try to attach, it fails:
CREATE DATABASE Galactic2  
ON (FILENAME = 'C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\Galactic.mdf'),
(FILENAME = 'C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\Galactic._Log.ldf')
FOR ATTACH;


Error:
Msg 5120, Level 16, State 101, Line 3
Unable to open the physical file "C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\Galactic.mdf". Operating system error 2: "2(The system cannot find the file specified.)".
Msg 1802, Level 16, State 7, Line 3
CREATE DATABASE failed. Some file names listed could not be created. Check related errors.

I'm working on my laptop, and I'm the local admin. Still no joy. What am I doing wrong? Do I have to change the permissions on the individual MDF and LDF files?

Does the SQL Server service account have NTFS privs to the file? If not, you have have to adjust the permissions.

I know your error refers to the MDF file, but I also have to ask if your log filename is correct. You have it as "Galactic._Log.ldf", with a period before the underscore. It may be right; just wanted to make sure.



Tally Tables - Performance Personified
String Splitting with True Performance
Best practices on how to ask questions
pietlinden
pietlinden
SSC Guru
SSC Guru (52K reputation)SSC Guru (52K reputation)SSC Guru (52K reputation)SSC Guru (52K reputation)SSC Guru (52K reputation)SSC Guru (52K reputation)SSC Guru (52K reputation)SSC Guru (52K reputation)

Group: General Forum Members
Points: 52022 Visits: 16664
The MSSQLSERVER (NT Service) has full permissions to the file(s). I never moved the files between uninstalling SQL Server and reinstalling it. Still no joy.
GilaMonster
GilaMonster
SSC Guru
SSC Guru (895K reputation)SSC Guru (895K reputation)SSC Guru (895K reputation)SSC Guru (895K reputation)SSC Guru (895K reputation)SSC Guru (895K reputation)SSC Guru (895K reputation)SSC Guru (895K reputation)

Group: General Forum Members
Points: 895970 Visits: 48655
The error's a 'file not found', so the obvious question is, is the file there?

Double-check that path please, because it doesn't look correct
C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\Galactic.mdf


With default installation settings, that should be C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQLSERVER\MSSQL\Data\Galactic.mdf
Similar for the log file (whose name also looks wrong, Galactic_log.ldf would be the default name)

Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


Lincoln Burrows
Lincoln Burrows
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16430 Visits: 1993
Here is a step by step solution for SQL Server Error 5120
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum








































































































































































SQLServerCentral


Search