Solved

Database Attach is failed…

Posted on 2011-09-05
14
463 Views
Last Modified: 2012-05-12
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
0
Comment
Question by:Mike Eghtebas
14 Comments
 
LVL 2

Accepted Solution

by:
awarren85 earned 100 total points
Comment Utility
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
 
LVL 21

Expert Comment

by:Alpesh Patel
Comment Utility
Please make sure the logged in user has permission to that folder for file read and write (proper).
0
 
LVL 16

Assisted Solution

by:EvilPostIt
EvilPostIt earned 400 total points
Comment Utility
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
 
LVL 33

Author Comment

by:Mike Eghtebas
Comment Utility
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
 
LVL 33

Author Comment

by:Mike Eghtebas
Comment Utility
Screen shot.
AttachError.png
0
 
LVL 16

Assisted Solution

by:EvilPostIt
EvilPostIt earned 400 total points
Comment Utility
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
 
LVL 33

Author Comment

by:Mike Eghtebas
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 16

Assisted Solution

by:EvilPostIt
EvilPostIt earned 400 total points
Comment Utility
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
 
LVL 33

Author Comment

by:Mike Eghtebas
Comment Utility
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
 
LVL 23

Expert Comment

by:Racim BOUDJAKDJI
Comment Utility
Also make sure that your SQL Server service has suficient priviledges to read and writ from the copied files.
0
 
LVL 33

Author Comment

by:Mike Eghtebas
Comment Utility
Racimo,

Two out of three is installed. Therefore, priviledges most likely is not the problem.
0
 
LVL 16

Expert Comment

by:EvilPostIt
Comment Utility
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
 
LVL 33

Author Comment

by:Mike Eghtebas
Comment Utility
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
 
LVL 16

Assisted Solution

by:EvilPostIt
EvilPostIt earned 400 total points
Comment Utility
AdventureWorks2008 is the correct name.

If you run this in a query windows do you get the same error?
0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now