tags:

views:

24

answers:

2

In SQL Server 2008 I can attach databases located only in its predefined folder (C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA). On may occasions, especially when I read a book, I need to attach test database from desktop rather then copy each database every time I need it, but SQL Server does not allow me to access desktop.

Any workaround to solve this issue?

+1  A: 

It's probably a matter of granting the account running the SQL service appropriate permissions to your desktop folder (C:\Documents and Settings\YourLogin\Desktop). But, rather than use a location like Desktop that is specific to your login and possibly inaccessible to the account running the SQL service, why not use a common holding location for these files? Something like C:\AdHocDBs or whatever you want to call it.

Joe Stefanelli
Well it's not just desktop, but mainly is because when I download something, it's downloaded on Desktop. Anyway, I'll try the trick with permissions.
askmo
I use Windows authentication for logging onto SQL Server. Any ideas which user should be permitted access? I already have 3 users granted access: SYSTEM, myself and Administrators.
askmo
More than likely, it's the NETWORK SERVICE account. You can verify by running `services.msc` from a command prompt and then checking the "Log On As" column for the "SQL Server" service.
Joe Stefanelli
Permission helped. THANKS!
askmo
A: 

When a database file (data or log) is first created, it is (of course) located in a specific drive and folder. When a backup is created, this information is stored as part of the backup. A database RESTORE command will assume that the database is to be restored in the exact same location, unless instructed otherwise. To do this, in the RESTORE command under the "with" option, you must include the "move" option. It looks something like this:

RESTORE ...
 with 
   move '<logcalFileName>' to 'physicalFileName'
  ,move '<logcalLogFileName>' to 'physicalLogFileName'

One move must be included for each file to be so moved, so you usually end up with at least two of these clauses. The tricky part is that you must know the database files' logical names. These can be found via sp_helpFile on an attached database, and

RESTORE FILELISTONLY
 from disk = '<backupFile>'

On an existing backup.

(I'm sure all this can be done somehow with the SSMS backup/restore GUIs. I switched over to TSQL-based scripts years ago, to provide quick and flexible access to all the features wrapped in the backup and restore commands.)

Philip Kelley
Thanks for trying to help, but I don't need this. I simply need to open .mdf database file from the folder I want.
askmo