Export (0) Print
Expand All

How to: Connect to a File-based Database

You can attach an existing database file to a local instance of SQL Server, or you can create a database file to attach to the local instance.

Important noteImportant Note:

You can connect only to SQL Server database files or SQL Server Express files. If you connect a SQL Server Express file to a local instance of SQL Server 2005, the file will be changed to the format for SQL Server 2005. If you connect a SQL Server Express file to a local instance of SQL Server 2008, then the file will be changed to the format for SQL Server 2008.

To temporarily attach a file-based database to the local SQL Server instance

  1. Right-click the Data Connections node in Server Explorer and choose Add Connection.

    The Add Connection dialog box appears.

  2. Click the Change button.

    The Change Data Source dialog box appears.

  3. Select Microsoft SQL Server Database File and click OK.

    The Add Connection dialog box reappears, with Microsoft SQL Server Database File (SqlClient) shown in the Data source text box.

  4. Click Browse and browse to an existing .mdf file.

    If you type a file name that does not exist, a blank .mdf file will be created.

  5. Select either Use Windows Authentication or Use SQL Server Authentication.

    For more information on SQL Server database access authentication, see Create New SQL Server Database Dialog Box.

  6. Click OK.

    The new database appears in Server Explorer. It will remain connected to SQL Server until you close the connection.

NoteNote:

You must have adequate Microsoft SQL Server permissions to create or attach a new database on the target server.

To permanently attach a file-based database

  1. Right-click the Data Connections node, and click Add New Connection.

    The Add Connection dialog box appears.

  2. In Server Name, type or browse to the path to the local instance of SQL Server.

    You can type "." for the default instance on your computer or ".\SQLEXPRESS" for the default instance of SQL Server Express.

  3. Click either Use Windows Authentication or Use SQL Server Authentication.

  4. Click Attach a database file, click Browse, and open an existing .mdf file.

  5. Click OK.

    The new database appears in Server Explorer. It will remain connected to SQL Server until you explicitly detach it.

Community Additions

ADD
Show:
© 2014 Microsoft