Microsoft SQL Server: How to attach database from network drive?

Yes, you can attach the database from network drive, please do with your own risk. Just follow the following command.

–Turn On Allow Attach from Network Drive (UNC)
DBCC TraceOn(1807)

–Attach the database
EXEC sp_attach_db @dbname = N’DatabaseName’,
   @filename1 = N’\\ServerName\SQL Data\DatabaseName_Data.MDF’,
   @filename2 = N’\\ServerName\SQL Log\DatabaseName_Log.LDF’

–Turn Off Allow Attach from Network Drive (UNC)
DBCC TraceOff(1807)

Advertisements

4 Responses to Microsoft SQL Server: How to attach database from network drive?

  1. Mahesh Kumar says:

    Best website to book bus tickets

  2. Harsha says:

    Which version of SQL Server supports attach database from network drive 2005/2008(r2)/2012???

    • guozspace says:

      This was tried on SQL Server 2005 & I believe it will applicable to newer version as well.

  3. Chris Lawton says:

    I dont know if this is possible, so I thought I would take it to the best SQL guy I could find. I’m trying to migrate a database from 1 server to another with the minimum down time possible. Thanks to this article I can take down the old server and attach the files to the new server, but then I would like to create a local mirror of the datafiles (2 datafiles for 1 database with the same content in both files), once the files are in sync drop the remote datafile and have the database stay up. I have done similar to this in Sybase, but I can’t find anywhere to create a mirrored datafile in MSSQL. Is this possible?
    Thank you very much
    Chris

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s