Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Attach a remotely stored database

Is it possible to attach a database that is stored on a remote server because when I mapped a drive and tried to attach it in management studio, the drive does not show up as an option. I moved it because of disk space and if I cannot what is the alternative suggestions?

like image 608
vbNewbie Avatar asked Aug 01 '26 06:08

vbNewbie


1 Answers

You should be able to attach a database on UNC path (I wouldn't use a mapped drive - that drive is mapped for you, not the SQL Server service account), but you have to ensure that the SQL Server service account has read/write permissions on the remote folder, and you have to run trace flag 1807 (please read Brent Ozar's post about this).

Also don't use the GUI for this. Once you have the trace flag set, have restarted the service, and have configured permissions correctly, use a new query window, and run the following command:

CREATE DATABASE db_name 
ON (Filename = '\\uncpath\share\file.mdf'),
   (Filename = '\\uncpath\share\file.ldf')
FOR ATTACH;

(The UI is never going to offer you a UNC path no matter what trace flags you have set or what permissions are enabled.)

Be prepared to handle a corrupted and possibly unrecoverable database should the network share go down, of course.

If that sounds scary to you, good! It should! This is not a good idea at all. Instead you should free up some space, add a drive, or host the database on a different instance.

like image 198
Aaron Bertrand Avatar answered Aug 06 '26 09:08

Aaron Bertrand



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!