Building ASP.NET Web Applications with Oracle Developer Tools for Visual Studio

 

Before You Begin

Purpose

This tutorial describes how you can build ASP.NET web applications that access Oracle Database using Oracle Developer Tools for Visual Studio.

Time to Complete

Approximately 30 minutes

Background

Oracle Developer Tools for Visual Studio is a tightly integrated "add-in" for Visual Studio. This tight integration makes it easy to create ASP.NET Web Applications that access Oracle database with minimal coding. This tutorial will guide you how to create such an application.

What Do You Need?

Before starting this tutorial, you should:
  1. Install Microsoft Visual Studio 2015 or later.
  2. Have access to Oracle Database 12c or later.
  3. Install Oracle Data Access Components (ODAC) 12c Release 4 or later from OTN. Be sure to use the Oracle Universal Installer and include Oracle Developer Tools for Visual Studio as part of the installation. During the install process, choose the machine-wide configuration option.
 

Creating a Web Site

In this section, you will create a new ASP.NET web site.

  1. Open Visual Studio. Click File. Select New > Web Site.

    Building ASP.NET Web Applications
    Description of this image
  2. Select Installed > Templates > Visual C# >ASP.NET Web Forms Site. Click OK.

    Building ASP.NET Web Applications
    Description of this image
  3. Observe the screen. The project WebSite1 opens up and the Default.aspx file displays on screen.

    Building ASP.NET Web Applications
    Description of this image
 

Creating the GridView

In this section, you will create a grid view in the web page. The grid view will display the retrieved Oracle data when the application is run.

  1. Click the Design tab in the Default.aspx page.

    Building ASP.NET Web Applications
    Description of this image
  2. Select to highlight the text in the MainContent(Custom) region in the Default.aspx page

    Building ASP.NET Web Applications
    Description of this image
  3. Delete the selected text by clicking the delete key.

    Building ASP.NET Web Applications
    Description of this image
  4. Select Toolbox, from the View menu. The Toolbox appears.

    Building ASP.NET Web Applications
    Description of this image
  5. Drag the GridView control under the Data in the Toolbox, to the Default.aspx Design area.

    Building ASP.NET Web Applications
    Description of this image
  6. Observe the screen. The design area gets the GridView control.

    Building ASP.NET Web Applications
    Description of this image
    Note: You can open the GridView task pane, by clicking the < symbol on the top right corner of the GridView.
 

Creating a Data Source

In this section, you will create a new Oracle data source for the grid in the ASP.NET web site. That will allow the grid to retrieve and show Oracle data when the web site is run.

  1. Goto Choose Data Source field in the Grid View tasks. Select <New data source...> from the Choose Data Source dropdown.

    Building ASP.NET Web Applications
    Description of this image
  2. The Data Source Configuration Wizard opens up. We will retrieve data from the Oracle HR sample schema. Select Database in the Where will the application get data from? field. Enter HR in the Specify an ID for the data source field. Click OK.

    Building ASP.NET Web Applications
    Description of this image
  3. The Configure Data Source wizard opens up. Click New Connection... in the Which data connection should your application use to connect to the database? field.

    Building ASP.NET Web Applications
    Description of this image
  4. The Add Connection dialog box opens. If Data Source is not already set to Oracle Database (ODP.NET, Managed Driver), click Change...

    Building ASP.NET Web Applications
    Description of this image
  5. In the Change Data Source dialog box, select Oracle Database as the Data Source and ODP.NET, Managed Driver as the Data Provider. Click OK. This step is required only if Data Source is not already set to Oracle Database (ODP.NET, Managed Driver).

    Building ASP.NET Web Applications
    Description of this image
  6. Enter the following details in the Add Connection dialog box and click OK.

    • User name: HR
    • Password: HR
    • Data source name: ORCL
    Building ASP.NET Web Applications
    Description of this image
    Note: The connection information may be different for your specific database setup.
  7. Connection string configuration is complete. Click Next in the Configure Data Source wizard.

    Building ASP.NET Web Applications
    Description of this image
  8. Click Next to save the connection string in the application configuration file.

    Building ASP.NET Web Applications
    Description of this image
  9. We will now choose the data to retrieve from the database. In this tutorial, we will select all columns and rows from the EMPLOYEES table. Choose the Specify columns from a table or view option. Select EMPLOYEES option from the name drop down. Select * from the columns check box. Click Next.

    Building ASP.NET Web Applications
    Description of this image
  10. Click Test Query to verify the query's validity.

    Building ASP.NET Web Applications
    Description of this image
  11. Observe the screen. The result of the query is shown. Click Finish.

    Building ASP.NET Web Applications
    Description of this image
  12. We can organize the data to make it easier for the end user to consume, such as enabling pagination. Select the Enable Paging check box in the Grid View tasks.

    Building ASP.NET Web Applications
    Description of this image
 

Executing the web site

In this section, you will run the ASP.NET web site and view the results returned from the Oracle database.

  1. Select Build > Build Web Site.

    Building ASP.NET Web Applications
    Description of this image
    Check in the output window for any errors reported. If no errors or warnings, proceed with the next step.
  2. Select Debug > Start Without Debugging.

    Building ASP.NET Web Applications
    Description of this image
  3. Observe the output. The query results are displayed. Browse through the results using pagination. Close the application.

    Building ASP.NET Web Applications
    Description of this image
    Note: If you are using Internet Explorer, make sure that it is not in "Work Offline" mode as it doesn't operate as expected in this mode.
 

Want to Learn More?