Partager via


Create a Database Connection String (IIS 7)

Applies To: Windows 7, Windows Server 2008, Windows Server 2008 R2, Windows Vista

If you use a database to store data for your applications, you can create a connection string in IIS to store the information that an application uses to connect to the database.

Note

Adding a configuration setting adds the setting at the local level and to any child levels that inherit the setting.

Prerequisites

For information about the levels at which you can perform this procedure, and the modules, handlers, and permissions that are required to perform this procedure, see Database Connection Strings Feature Requirements (IIS 7).

Exceptions to feature requirements

  • None

To create a database connection string

You can perform this procedure by using the user interface (UI), by running Appcmd.exe commands in a command-line window, by editing configuration files directly, or by writing WMI scripts.

User Interface

To Use the UI

  1. Open IIS Manager and navigate to the level you want to manage. For information about opening IIS Manager, see Open IIS Manager (IIS 7). For information about navigating to locations in the UI, see Navigation in IIS Manager (IIS 7).

  2. In Features View, double-click Connection Strings.

  3. On the Connection Strings page, click Add in the Actions pane.

  4. In the Add Connection String dialog box, type a name for the connection string, such as MyConnection, in the Name text box.

Note

The name that you enter in IIS Manager should be the same name that you reference in your application code to retrieve data by using this connection string.

  1. With the SQL Server option selected, type the name of the server that hosts the database in the Server text box and type the name of the database in the Database text box.

  2. Under Credentials:

    • Select Use Windows Integrated Security.

      -Or-

    • Select Specify credentials and click Set. Type a user name and password for an account that can connect to the server and database in the User name and Password text boxes. Then type the same password in the Confirm password text box, and click OK.

  3. Click OK.

Command-line

To create a database connection string, use the following syntax:

appcmd set config /commit:MACHINE /section:connectionStrings /+"[connectionString='string',name='string',providerName='string']"

The variable connectionString string is the connection string value, the variable name string is the key to use to access the connection string value, and the variable providerName string is the name of the ADO.NET provider to use to access the underlying data store. For example, to create a connection string for an application that uses the Northwind database, type the following at the command prompt, and then press Enter:

appcmd set config /commit:MACHINE /section:connectionStrings /+"[connectionString='Data Source=localhost;Integrated Security=SSPI;Initial Catalog=Northwind;',name='Northwind',providerName='System.Data.SqlClient ']"

For more information about Appcmd.exe, see Appcmd.exe (IIS 7).

Configuration

The procedure in this topic affects the following configuration elements:

  • <connectionStrings>

For more information about IIS 7 configuration, see IIS 7.0: IIS Settings Schema on MSDN.

WMI

Use the following WMI classes, methods, or properties to perform this procedure:

  • ConnectionStringsSection.Add method

For more information about WMI and IIS, see Windows Management Instrumentation (WMI) in IIS 7. For more information about the classes, methods, or properties associated with this procedure, see the IIS WMI Provider Reference on the MSDN site.

See Also

Concepts

Configuring Connection Strings in IIS 7