dbaspot
Tags Register FAQ Calendar Search Today's Posts Mark Forums Read

Attach a sql2005 database at a different directory - sqlserver-faq

This is a discussion on Attach a sql2005 database at a different directory - sqlserver-faq ; I create a database ("a") in SQL 2005 Express using Microsoft SQL Server Management Studio Express. I then detach the database "a", copy the two file in C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data to another directory d:\test\ I then try to attach ...


Home > Database Forum > Microsoft SQL Server > sqlserver-faq > Attach a sql2005 database at a different directory

Reply

 

LinkBack (2) Thread Tools Display Modes
  2 links from elsewhere to this Post. Click to view. #1  
Old 06-05-2007, 05:53 AM
Database Bot
 
Join Date: Sep 2009
Posts: 1,236,254
Database Administrator is on a distinguished road
Default Attach a sql2005 database at a different directory

I create a database ("a") in SQL 2005 Express using Microsoft SQL Server
Management Studio Express.

I then detach the database "a", copy the two file in C:\Program
Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data to another directory d:\test\

I then try to attach it. It gives the following messages. What should I do
to succesful attach a database in a different directory?

Attach database failed for Server 'ASUSTANG2\SQLEXPRESS'.
(Microsoft.SqlServer.Express.Smo)
An exception occurred while executing a Transact-SQL statement or batch.
(Microsoft.SqlServer.Express.ConnectionInfo)
Unable to open the physical file "D:\Test\a.mdf". Operating system error 5:
"5(Access is denied.)". (Microsoft SQL Server, Error: 5120)

Reply With Quote
  #2  
Old 06-05-2007, 06:58 AM
Database Bot
 
Join Date: Sep 2009
Posts: 1,236,254
Database Administrator is on a distinguished road
Default Re: Attach a sql2005 database at a different directory

Under what account is the SQL Server service running? Does that account
have read/write privileges on that directory?

--
Tom

----------------------------------------------------
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS
SQL Server MVP
Toronto, ON Canada
https://mvp.support.microsoft.com/profile/Tom.Moreau


"David" wrote in message
news:990411BC-958D-481A-B679-C6DCEEE120AB@microsoft.com...
I create a database ("a") in SQL 2005 Express using Microsoft SQL Server
Management Studio Express.

I then detach the database "a", copy the two file in C:\Program
Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data to another directory d:\test\

I then try to attach it. It gives the following messages. What should I do
to succesful attach a database in a different directory?

Attach database failed for Server 'ASUSTANG2\SQLEXPRESS'.
(Microsoft.SqlServer.Express.Smo)
An exception occurred while executing a Transact-SQL statement or batch.
(Microsoft.SqlServer.Express.ConnectionInfo)
Unable to open the physical file "D:\Test\a.mdf". Operating system error 5:
"5(Access is denied.)". (Microsoft SQL Server, Error: 5120)

Reply With Quote
  #3  
Old 06-05-2007, 09:49 PM
Database Bot
 
Join Date: Sep 2009
Posts: 1,236,254
Database Administrator is on a distinguished road
Default Re: Attach a sql2005 database at a different directory

Hello,

Use SQL Server configuration manager from SQL Server 2005 program
goups...There select sql server 2005 services and choose sql server service
and see the Logon account.
If the account is not local system then change it to Local system and then
restart the service and see if the attch works. If it works then give the
necessary previlages to the
toher account and restart the service and see if the attach works fromm D
Drive..

Thanks
Hari

"David" wrote in message
news:990411BC-958D-481A-B679-C6DCEEE120AB@microsoft.com...
>I create a database ("a") in SQL 2005 Express using Microsoft SQL Server
>Management Studio Express.
>
> I then detach the database "a", copy the two file in C:\Program
> Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data to another directory
> d:\test\
>
> I then try to attach it. It gives the following messages. What should I do
> to succesful attach a database in a different directory?
>
> Attach database failed for Server 'ASUSTANG2\SQLEXPRESS'.
> (Microsoft.SqlServer.Express.Smo)
> An exception occurred while executing a Transact-SQL statement or batch.
> (Microsoft.SqlServer.Express.ConnectionInfo)
> Unable to open the physical file "D:\Test\a.mdf". Operating system error
> 5: "5(Access is denied.)". (Microsoft SQL Server, Error: 5120)
>



Reply With Quote
  #4  
Old 03-29-2009, 06:24 PM
Database Newbie
 
Join Date: Mar 2009
Posts: 1
andrewzino is on a distinguished road
Thumbs up Re: Attach a sql2005 database at a different directory

Dear Hari,

Thank you so much for your insructions - I have manged to get my database back online.

You are a legend!

Andrew
Reply With Quote
  #5  
Old 10-07-2009, 11:40 AM
Database Newbie
 
Join Date: Oct 2009
Posts: 1
bimkaz269 is on a distinguished road
Smile Re: Attach a sql2005 database at a different directory

thanks hari, it worked
Reply With Quote
  #6  
Old 11-19-2009, 09:27 PM
Database Newbie
 
Join Date: Nov 2009
Location: Madison, Connecticut
Posts: 1
RickRoyston is on a distinguished road
Smile Re: Attach a sql2005 database at a different directory

I recently upgraded from Vista (32-bit) to Windows 7 (64-bit). Although I carefully backed up all my data files, I was unaware that I was supposed to create a specific data backup file from within Business Contact Manager. As a result, I found myself unable to restore my Business Contact Manager database.

I'd tried to restore my data using various methods that I'd found in various online posts, including:
- running a specific SQL script;
- changing permissions on the Business Contact Manager folders and files;
- Starting Outlook in Administrator mode; and
- reinstalling Business Contact Manager.

None of these methods worked. Then I found yours, and it worked perfectly!

Many thanks for sharing your expertise. I'll be surprised if I'm the only Windows 7 upgrader who benefits from your posting!

Thanks

Rick in Connecticut
Reply With Quote
Reply

Thread Tools
Display Modes


LinkBacks (?)

LinkBack to this Thread: http://dbaspot.com/forums/sqlserver-faq/230596-attach-sql2005-database-different-directory.html

Posted By For Type Date
Removed and reinstalled BCM now can't see old .mdf file This thread Refback 04-28-2009 08:37 AM
Removed and reinstalled BCM now can't see old .mdf file | keyongtech This thread Pingback 03-29-2009 07:06 PM


All times are GMT -4. The time now is 03:22 AM.