Attaching and Detaching a Microsoft SQL Server Database.

August 4, 2005 | KB: 1011003
Server (MSDE) 7, Server (MSSQL) 7

Summary

In some cases, it may be necessary to attach or detach a database from its Microsoft SQL Server instance. For example, moving the database will require you to detach the database, move the database files, and then reattach the database.

In most situations, the Laserfiche Repository Creation and Repository Registration wizards will handle attaching and detaching Microsoft SQL Server Desktop Edition (MSDE) and MSSQL: Personal Edition databases automatically. However, in some circumstances, such as if the database files are not in the repository path, it may be necessary to manually attach or detach the database.

More Information

There are two primary ways to attach and detach Microsoft SQL Server databases. If SQL Server Enterprise Manager is available, it should be used to perform these functions. SQL Server Enterprise Manager is packaged with Microsoft SQL Server 2000 and Microsoft SQL Server: Personal Edition. If Enterprise Manager is not available, the databases must be attached and detached using OSQL commands. Scripts that will automatically run those commands are available in the following instructions.

To attach a database using Enterprise Manager

  1. Open Enterprise Manager.
  2. Expand Microsoft SQL Servers.
  3. Expand SQL Server Group.
  4. Expand the SQL Server to which you wish to attach the database.
  5. Select Databases.
  6. From the Action menu, select All Tasks and then click Attach Database.
  7. Specify the path to the .mdf file of the database you wish to attach.
  8. Click OK.
  9. If you are attaching an MSDE or MSSQL: Personal Edition database, repeat steps 6-8 for each expansion database.

To detach a database using Enterprise Manager

  1. Open Enterprise Manager.
  2. Expand Microsoft SQL Servers.
  3. Expand SQL Server Group.
  4. Expand the SQL Server on which the database you wish to detach is located.
  5. Expand Databases.
  6. Select the database you wish to detach.
  7. From the Action menu, select All Tasks and then click Detach Database.
  8. If there are any connections currently using this database, you will need to clear them. Select Clear. When prompted, select whether you wish current users to be notified that their connections will be disconnected.
  9. Click OK.
  10. If you are detaching an MSDE or MSSQL: Personal Edition database, repeat steps 6-9 for each expansion database.

To attach a database using a VBScript file containing OSQL commands

  1. Click here to download a vbscript file to attach a database.
  2. Double-click AttachDb.vbs to run the script.
  3. In the first dialog box, type the name of your Microsoft SQL Server and click OK.
  4. In the second dialog box, type the name of the database you want to attach and click OK.
  5. In the third dialog box, type the full path to the MDF file of the database and click OK.
  6. In the fourth dialog box, type the full path to the LDF file of the database and click OK.
  7. If you are attaching an MSDE or MSSQL: Personal Edition database, repeat steps 2-5 for each expansion database.

To detach a database using a VBScript containing OSQL commands

  1. Click here to download a vbscript file to detach a database.
  2. Double-click DetachDB.vbs to run the script.
  3. In the first dialog box, type the name of your Microsoft SQL server and click OK.
  4. In the second dialog box, type in the name of the database that you want to detach and click OK.
  5. If you are detaching an MSDE or MSSQL: Personal Edition database, repeat steps 2-4 for each expansion database.

Related Links

For more information on managing your MSDE database, see the following Microsoft Knowledge Base article:

How to Manage the SQL Server Desktop Engine (MSDE 2000) by Using the Osql Utility.