다음을 통해 공유


Database Connections and Database References

You can work with databases using both Server Explorer/Database Explorer and Solution Explorer. While these tools both provide access to databases, they differ somewhat in concept and functionality. For example, while Server Explorer/Database Explorer lets you establish database connections, Solution Explorer lets you establish database references. There are both similarities and differences between database connections and database references.

Note

In Visual Studio 2013, you can connect to a SQL Server database from either SQL Server Object Explorer or the Data Connections node in Server Explorer. SQL Server Object Explorer provides a view that is like SQL Server Management Studio. To open this explorer from the menu bar, choose View, SQL Server Object Explorer. For more information, see Connected Database Development.

How Database Connections and Database References Are Similar

Both a database connection and a database reference are active links to a database letting you read and write data and create SQL objects in the database (subject to the permissions you have in the database).

In addition, there are some dialog boxes that combine the list of database references and database connections. For example, if you are working on a database project, and you want to run one of that project's SQL scripts on a particular database, you can right-click the script and choose Run On from the shortcut menu. The Run On dialog box appears, containing a list of all database references from the project and all database connections from Server Explorer/Database Explorer. To run the query, you can choose any item from the list, either a database reference or a database connection.

How Database Connections and Database References Are Different

The differences between a database connection and a database reference fall into three categories:

  • Appearance   A database connection appears in Server Explorer/Database Explorer, under the Data Connections node or SQL Server node. In contrast, a database reference appears in a database project within Solution Explorer, under the Database References node.

  • Possible User Actions   In Server Explorer/Database Explorer, you can expand a database connection to view and manipulate objects in the database. For example, you can see a list of the database's tables, and you can add a table to the database. In Solution Explorer, you cannot expand a reference to view or manipulate database objects.

    Using Solution Explorer to maintain a set of database references for each database project is useful for several reasons. First, you can maintain several database references for a database project. As you develop and test your database project, you might choose to keep one reference to a personal test database on your own machine and another reference to a group-wide test database that you share with your colleagues. Second, when you save a database project, the set of database references is saved with the project. When you reopen the project, the database references and associated connections are available to you.

    In Solution Explorer, you can easily execute scripts by dragging them to a database reference.

  • Interactions   There are certain interactions that occur between database connections and database references. When you create a database connection in Server Explorer/Database Explorer, it has no direct effect on the contents of Solution Explorer. But when you use Solution Explorer to create a database reference for a database project, you must specify a database connection that will appear in Server Explorer/Database Explorer. You can select from a list of existing database connections or add a new connection.

See Also

Tasks

How to: Connect to a Database from Server Explorer

Reference

Add/Modify Connection Dialog Box (General)