Solved

Database Attach is failed…

Posted on 2011-09-05
14
468 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
14 Comments
 
LVL 2

Accepted Solution

by:
awarren85 earned 100 total points
ID: 36486437
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
ID: 36486764
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
ID: 36487051
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
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
LVL 34

Author Comment

by:Mike Eghtebas
ID: 36487790
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 34

Author Comment

by:Mike Eghtebas
ID: 36487886
Screen shot.
AttachError.png
0
 
LVL 16

Assisted Solution

by:EvilPostIt
EvilPostIt earned 400 total points
ID: 36488660
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 34

Author Comment

by:Mike Eghtebas
ID: 36489359
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
 
LVL 16

Assisted Solution

by:EvilPostIt
EvilPostIt earned 400 total points
ID: 36489460
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 34

Author Comment

by:Mike Eghtebas
ID: 36489589
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
ID: 36502470
Also make sure that your SQL Server service has suficient priviledges to read and writ from the copied files.
0
 
LVL 34

Author Comment

by:Mike Eghtebas
ID: 36506785
Racimo,

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

Expert Comment

by:EvilPostIt
ID: 36508653
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 34

Author Comment

by:Mike Eghtebas
ID: 36515276
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
ID: 36521585
AdventureWorks2008 is the correct name.

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

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

724 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