Share via

How to: Create Connections to SQL Server Databases

You can connect your application to data in a SQL Server database using the .NET Framework Data Provider for SQL Server.

Whether you are creating data connections with one of the data wizards or with Server Explorer/Database Explorer, the process of defining your connection is the same; you choose a data source in the Choose/Change Data Source Dialog Box and add connection information in the Add/Modify Connection Dialog Box (General).


The dialog boxes and menu commands you see might differ from those described in Help depending on your active settings or edition. To change your settings, choose Import and Export Settings on the Tools menu. For more information, see Visual Studio Settings.

Creating a Data Connection to a SQL Server Database

To create a data connection to a SQL Server database

  1. In Server Explorer/Database Explorer click Connect to Database.

  2. In the Choose Data Source dialog box, select Microsoft SQL Server, and then click OK.

    If the Add Connection dialog box opens, and the Data source is not Microsoft SQL Server, click Change to open the Choose/Change Data Source dialog box. For more information, see Choose/Change Data Source Dialog Box.

  3. Select a server name from the drop-down list, or type the name of the server where the database you want to access is located.

  4. Based on the requirements of your database or application, select either Windows Authentication or use a specific user name and password to log on to the SQL Server (SQL Server Authentication). For more information, see Add/Modify Connection (Microsoft SQL Server).

  5. Select the database you want to connect to from the drop-down list.

  6. Click OK.


Storing connection-string details (such as a password) can affect the security of your application. Using Windows integrated security is a more secure way to control access to a database. For more information, see Protecting Connection Information (ADO.NET).

See Also


How to: Connect to Data in a Database

Walkthrough: Connecting to Data in a Database


Data Source Configuration Wizard

Other Resources

Connecting to Data in Visual Studio

Preparing Your Application to Receive Data

Fetching Data into Your Application

Displaying Data on Forms in Windows Applications

Editing Data in Your Application

Validating Data

Saving Data