?
Solved

How do I attach a database to an instance of SQL Server 2005 Express?

Posted on 2007-10-15
3
Medium Priority
?
396 Views
Last Modified: 2012-05-05
Experts: I am trying to attach the sample database AdventureWorks to an instance of SQL Server 2005 Express. Using the following code:
USE MASTER
GO

CREATE DATABASE AdventureWorks
ON PRIMARY (FILENAME = 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\AdventureWorks_Data.mdf')
FOR ATTACH
GO

I get a message:
Msg 5120, Level 16, State 101, Line 2
Unable to open the physical file "C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\AdventureWorks_Data.mdf". Operating system error 5: "5(Access is denied.)".

I have checked the properties of the file and it is not read only. Would appreciate your assistance.
0
Comment
Question by:jbotts
3 Comments
 
LVL 7

Accepted Solution

by:
assyst earned 500 total points
ID: 20082654
Can you copy the mdf & ldf file to some other location and then try attaching it.
0
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 20082694
EXEC sp_attach_single_file_db @dbname = 'AdventureWorks',
   @physname =  'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\AdventureWorks_Data.mdf'
0
 

Author Comment

by:jbotts
ID: 20082931
I don't know why this worked, buit it did.
Thanks,
Jim Botts
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Loops Section Overview
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…

864 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