Gets or sets the ADO.NET provider–specific connection string that the SqlDataSource control uses to connect to an underlying database.
Assembly: System.Web (in System.Web.dll)
The SqlDataSource control can be used with a variety of ADO.NET providers and the syntax of the connection string that is used to connect to an underlying data source is specific to the provider.
When you configure a SqlDataSource control, you set the ProviderName property to the type of database (the default is System.Data.SqlClient), and you set the property to a connection string that includes information that is required in order to connect to the database. The contents of a connection string differ depending on what type of database the data source control is accessing. For example, the SqlDataSource control requires a server name, database (catalog) name, and information about how to authenticate the user when connecting to a SQL Server. For information about the contents of connection strings, see the ConnectionString property for the SqlConnection class, ConnectionString property for the OracleConnection class, ConnectionString property for the OleDbConnection class, or the ConnectionString property for the OdbcConnection class.
For information about storing a connection string, see How To: Secure Connection Strings when Using Data Source Controls.
This section contains two code examples. The first code example demonstrates how to set the SelectCommand property in a GridView control. The second code example demonstrates a more complex scenario, where a SqlDataSource control is used to display and update data in a password-protected Microsoft Access database. In each case, the connectionStrings element of the Web.config file is shown first, followed by the ASP.NET page that contains the SqlDataSource control.property to connect to a Microsoft SQL Server database and display the results of the
The following code example demonstrates a more complex scenario than the preceding code example, where a SqlDataSource control is used to display and update data in a password-protected Access database. Because the SqlDataSource is used with Access, the ProviderName property is set to the System.Data.OleDb provider, and the property is set to an appropriate connection string for a UNC-shared Access database. A GridView control displays orders with shipment dates. You can update an order by checking the appropriate check box, and then clicking the Update button.
This example includes a password in plain text only for illustration purposes. In a production application, connection strings that include passwords should be encrypted. For more information, see Protecting Connection Information.
Available since 2.0