Database Attach is failed…

MCTS Training Kit requires installation of 3 databases. Two of them are attached properly (I guess). When I run queries against their tables it works fine.

Q1: Does running queries show these two databases are installed/attached properly? If not, then what other test I need to do to make sure?

The 3rd database, in addition to its *.mdf and *.ldf files, has a folder named “Ducuments” which has some other files and subfolder in it.

During my first attempt, I hadn’t copied this folder to my “C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA” from the Training Kit CD.

After getting the error, I copied “Documents” folder and tried to attach the database again but I still got the error. Please see the attached images for error description.

Q2: What do I need to do to install/attach the third database successfully?

Thank you.

IsAttachedErrMsg.png
IsAttachedErrMsgTechDetail.png
LVL 34
Mike EghtebasDatabase and Application DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

awarren85Commented:
For Q1:  Yes, if you're running queries successfully against the databases then you should be good.

For Q2:  Looks like it's looking at a specific directory in order to attach the database.  Try using the following instead in a SQL Window, if you can:

USE [master]
GO
CREATE DATABASE [AdventureWorks2008] ON
( FILENAME = N’C:\Data\AdventureWorks_Data.mdf’ ),
( FILENAME = N’C:\Data\AdventureWorks_Log.ldf’ )
FOR ATTACH
GO

Replace the C:\Data\***.mdf and the C:\Data\***.ldf lines above to where your .mdf and .ldf is stored on your computer.  If it complains about AdventureWorks2008 already existing, try the following first:

USE MASTER
GO
DROP DATABASE [AdventureWorks2008]

Good luck!
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Alpesh PatelAssistant ConsultantCommented:
Please make sure the logged in user has permission to that folder for file read and write (proper).
0
EvilPostItCommented:
Q1: If you can query the database then its attatched. If you want to ensure that there is not any corruption run DBCC CHECKDB against it.

Q2: In the windows you have supplied it is giving the error "Operating System Error 2: The system cannot find the specified file.". This is the issue, the supplied path is incorrect. If you look at the path it ends in just Documents.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Mike EghtebasDatabase and Application DeveloperAuthor Commented:
Re:> awarren85 Q2 solution
Most likely this solution would work. But I will prefer a solution with a less chance of harming or corrupting the SQL Server installation where I have to re-install it again. At first, I will try a solution I can have my arms around it so to speak.

Re:> PatelAlpesh comment
Two out of three databases have been attached properly. So, the user permit is less likely the cause of the error.

Re:> EvilPostIt posts
On Q1, what is the step by step procedure to run DBCC CHECKDB to detect corruption?

On Q2, in folder "C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA\Documents" I have:

- filestream.hdr
- $FSLOG--------       <-- subfolder
                       |placeholder.txt
                   
- 419cb40c-eaf5-4086-a60d-651ab009ceb0--------               <-- Subfolder
        |9da3685b-6938-4675-9e05-8b1d31a2621d--------      <--SubSubfolder
                       |0000001d-0000054b-00d0
                       |0000001d-0000056b-0007
                       |0000001e-00000010-000f
                       |0000001e-00000010-0001
                       |0000001e-00000010-001d
                       |0000001e-00000010-002b
                       |0000001e-00000010-0008
                       |0000001e-00000010-0016
                       |0000001e-00000010-0024

These are copied from the companion CD that comes with the book (MCTS Exam 70-433)

Is it possible some of these files are bad? Or, they have to be copied in a different fashion.

Please note from the original question: "During my first attempt, I hadn’t copied 'Documents' folder to my “C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA” folder from the Training Kit CD."

Now, is it possible because it (Documents folder) wasn't there on the first try; therefore,  something got corrupted? And, unless its effect is gone it will keep giving some error unless it is corrected. It is a wild shot but doesn't hurt considering it.

I like your approach because I am beginner so therefore more comfortable with it at this point.

Any additional comments from the experts?

Thanks to all,

Mike
                       
0
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
Screen shot.
AttachError.png
0
EvilPostItCommented:
Q1) The command would be DBCC CHECKDB (DBNAME)

Q2) From the looks of things there are no database files available to attatch. It should be an .mdf file and a .ldf file.
0
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
re:> Q1) The command would be DBCC CHECKDB (DBNAME)

Where and how you do this?

re:> Q2) From the looks of things there are no database files available to attatch. It should be an .mdf file and a .ldf file.

The file names in question are on the top of the list. Please see the attached partial image.

Thanks.
DatabaseName.png
0
EvilPostItCommented:
Use management studio.

http://www.microsoft.com/download/en/details.aspx?id=22985

It says to click the hyperlink for the message. Did you get the error?
0
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
re:> It says to click the hyperlink for the message. Did you get the error?

Yes, see the first image on the original question.

Also, on Q1, can you give me step 1, 2,... of it?
0
Racim BOUDJAKDJIDatabase Architect - Dba - Data ScientistCommented:
Also make sure that your SQL Server service has suficient priviledges to read and writ from the copied files.
0
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
Racimo,

Two out of three is installed. Therefore, priviledges most likely is not the problem.
0
EvilPostItCommented:
Can you run through the the entire attach operation and then hit the script out button (next to the help button at the top). Then post it here.
0
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
EvilPostIt,

After adding the database (and before hitting OK button to attach it), the script is below. After hitting OK button, it gives an error and script is no longer available.

I don't know why the code says:

CREATE DATABASE [AdventureWorks2008] ON...

I though it should say:

CREATE DATABASE [AdventureWorks2008_Data] ON...

I think, if I rename AdventureWorks2008 to another name, it might solve the problem. If so, what is the proper way of renaming it and its related parts (queries, views, etc) in one step?

Thanks,

Mike
USE [master]
GO
CREATE DATABASE [AdventureWorks2008] ON 
( FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA\AdventureWorks2008_Data.mdf' ),
( FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA\AdventureWorks2008_Log.ldf' )
 FOR ATTACH
GO

Open in new window

0
EvilPostItCommented:
AdventureWorks2008 is the correct name.

If you run this in a query windows do you get the same error?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.