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

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.
jbottsAsked:
Who is Participating?
 
assystConnect With a Mentor Commented:
Can you copy the mdf & ldf file to some other location and then try attaching it.
0
 
Aneesh RetnakaranDatabase AdministratorCommented:
EXEC sp_attach_single_file_db @dbname = 'AdventureWorks',
   @physname =  'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\AdventureWorks_Data.mdf'
0
 
jbottsAuthor Commented:
I don't know why this worked, buit it did.
Thanks,
Jim Botts
0
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.

All Courses

From novice to tech pro — start learning today.