JavaScript Editor jscript editor     Web designer 

Main Page

You can use the SqlDataSource control to connect to an Oracle database by storing connection string information in the Web application's Web.config file and then referencing the connection string from your SqlDataSource control.


N:System.Data.OracleClient managed provider requires Oracle client software version 8.1.7 or higher to be installed on the computer where the ASP.NET Web page runs.

To configure a connection string for Oracle in the Web.config file

  1. Open the Web.config file in the root directory of your ASP.NET application. If you do not have a Web.config file, create one.

  2. In the Configuration element, add a ConnectionStrings element if one does not already exist.

  3. Create an add element as a child of the ConnectionStrings element, defining the following attributes:

    • nameВ В В Set the value to the name that you want to use to reference the connection string.

    • connectionStringВ В В Assign the connection string that is required to connect to the Oracle database. For information about the connection string values you must use, contact your database administrator.

    • providerNameВ В В Assign the value "System.Data.OracleClient", which specifies that ASP.NET should use the ADO.NET System.Data.OracleClient provider when making a connection with this connection string.

      Your completed add element might look like the following:

      В CopyCode imageCopy Code
      <add name="OracleConnectionString"
        connectionString="Data Source=OracleServer1;Persist 
          Security Info=True;Password="******";User ID=User1"
        providerName="System.Data.OracleClient" />

      If you include explicit authentication information in a connection string, you should encrypt the ConnectionStrings section of the Web.config file. For details, see Encrypting Configuration Information Using Protected Configuration.

  4. Save the Web.config file.

To reference the Oracle connection string from a SqlDataSource control

  1. In the page in which you want to connect to the Oracle database, add a SqlDataSource control.

  2. In the SqlDataSource control, specify the following properties:

    • SelectCommandВ В В Set to the SQL select statement for retrieving data, as in the following example:

      В CopyCode imageCopy Code
      SelectCommand="select * from customers"
    • ConnectionStringВ В В Set to the name of the connection string that you created in the Web.config file.

    • ProviderNameВ В В Set to the name of the provider that you specified in the Web.config file.


      You can also define UpdateCommand, DeleteCommand, and InsertCommand properties. For more information, see SqlDataSource control.

    The SqlDataSource control declaration will be similar to the following:

    В CopyCode imageCopy Code
        ID="SqlDataSource1" Runat="server" 
        SelectCommand="select * from products"
        ConnectionString="<%$ ConnectionStrings:OracleConnectionString%>"
        ProviderName="<%$ ConnectionStrings:AppConnectionString1.ProviderName %>" />

See Also


Data Source Controls Overview

Other Resources

Using the .NET Framework Data Provider for Oracle

JavaScript Editor jscript editor     Web designer