Error attaching a database (.mdf file) to SQL Server

In midst of new DB server build and application testing, lately, we had received a request from application folks to fall back to last night backup set which had already been moved to Tape.

Seeking this as an urgent request, Wintel Support guy accidentally copied the datafiles (.mdf/.ldf) instead of the required backup set and we were asked to create a new testing DB using these datafiles.

Now, to start with the DB process, always ensure that the service account used to run SQL Server services has full access/control on the newly copied data files (There is a strong possibility that these files are copied to a new location, wherein your domain authenticated ID doesn’t have complete privileges and it may result in an error).

Having covered this prospect, we started with the attach DB process and encountered the following error-
2013-09-24 12:18:40.840 spid61       Error: 3415, Severity: 16, State: 3.
2013-09-24 12:18:40.840 spid61       Database ‘*******’ cannot be upgraded because it is read-only or has read-only files. Make the database or files writeable, and rerun recovery.

As per the current setup and scenario, both Source and Target Servers were running with same version/edition/service packs, so the error message looked a bit strange (Database cannot be upgraded).

Having ensured that permissions were in place and files were accessible, I tried to rename the physical files and it worked smoothly!

Quite strange, isn’t it? 🙂

Trick was to rename the physical files, and ensure that SQL Server service account had full control/access on the data files.

Hope this helps.

Cheers!!
Aman Kharbanda

Advertisements

Author: sqlserverposts

Database Consultant by profession. I am a geek and a avid sports lover too. "Progress informed by the past, inspired by future".

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s