Link to home
Start Free TrialLog in
Avatar of jbotts
jbotts

asked on

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.
ASKER CERTIFIED SOLUTION
Avatar of assyst
assyst

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Aneesh
EXEC sp_attach_single_file_db @dbname = 'AdventureWorks',
   @physname =  'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\AdventureWorks_Data.mdf'
Avatar of jbotts
jbotts

ASKER

I don't know why this worked, buit it did.
Thanks,
Jim Botts