logo for smart-soft-nz.com
[?] Subscribe To This Site

XML RSS
Add to Google
Add to My Yahoo!
Add to My MSN
Subscribe with Bloglines


Home
Smartsoft Blog
Oracle Training
Oracle 9i
Oracle 10g
Oracle 11g
Oracle App Server
Oracle Utilities
Backup and Recovery
Oracle Certification
Oracle Tutorials
PL/SQL
Free SQL Tutorial
SQL
News
Oracle Resources
Oracle Secrets Signup
Oracle and .Net
Contact Us
leftimage for smart-soft-nz.com

How To Build an ASP.NET Web Site Application With Oracle

Intended audience

This tutorial on using ASP.NET with Oracle is for developers who are unfamiliar with C# or experienced C# developers who are new to Oracle. It is designed to familiarize you with the basics of how to perform data manipulation in Oracle from C#. While security is an important consideration it is beyond the scope of this tutorial.

Prerequisites

  1. Install Microsoft Visual Studio 2008 for building your ASP.NET application
  2. Go to the Oracle Technology Network and install Oracle Database 10g XE. Make sure that you follow the instructions to enable the HR database. If you accepted the default settings of the installer 

the server is in C:\oraclexe. The listener.ora, sqlnet.ora and tnsnames.ora files are in c:\oraclexe\app\oracle\admin\XE\product\10.2.0\server\NETWORK\ADMIN.

3. Start the Oracle XE database.

4. Go to the Oracle Technology Network and install Oracle 11g Data Access Components (ODAC) with Oracle Developer Tools for Visual Studio 11.1.07.20 or later. If you accepted the default settings of the installer the ODAC is installed in c:\app.

5. Copy listener.ora, sqlnet.ora and tnsnames.ora from c:\oraclexe\ app\ oracle\ admin\ XE\ product\ 10.2.0\ server\ NETWORK\ ADMIN to c:\app\product\11.1.0\client_1\Network\Admin. This will prevent a TNS-12514: TNS: could not resolve the connect identifier error from appearing.

Use Visual Studio 2008 to create your first web site

  1. Bring up Visual Studio 2008
  2. Navigate to the File menu and select "New Web Site"

    Visual Studio 2008 - new website


  3. On the “New Web Site” page please select “ASP.NET Web Site”. Make sure you name it C:\MyFirstWebSite”. Set the language to “Visual C#”. Then click “OK”.

    Visual Studio 2008 ASP.NET

  4. When you see the “Default.aspx” page in your new ASP.NET web site please click the Design tab

    Visual Studio 2008 design tab

    A blank canvas will appear:

    Visual Studio 2008 blank canvas

  5. Do you see the “Toolbox” tab on the top left hand side of the screen? Move the mouse over it to bring up the Toolbox like this:

    Visual Studio 2008 toolbox

    Oracle Tips & Tricks to 
    SKYROCKET Your Career!

    If you're not already a subscriber to Oracle Secrets Revealed, you're  missing out on a myriad of tips and techniques to help you work better, faster and smarter.  Subscribe now and ignite your career.

  6. Make sure you expand Data and look for the GridView control. Then drag it to the canvas so that it will appear like this:

    Visual Studio 2008 grid control

  7. Now you will create a data source. In case you do not see the GridView Tasks view please click the ">" to bring it into view like the previous screenshot. Please select <New data source…>

    Visual Studio 2008 create data source

  8. Choose Database as the Data source type, enter HR as the ID and click “OK”.

    Visual Studio 2008 database data source

  9. Click on “New Connection”

    Visual Studio 2008 database connection

  10. This causes the Change Data Source Dialog box appear as in the screen shot below

    Visual Studio 2008 add connection
    Click the “Change…” button to ensure that the Oracle Database is selected as the data source for your ASP.NET site and the Data provider is set to the “Oracle Data Provider for .NET”. Click the check box beside “Always use this selection”. Now click "OK"

    Visual Studio 2008 change data source for ASP.NET app


  11. On the connection details tab of the “Add Connection” dialog box set the Data Source Name to “XE”. Enter “HR” for the user name and the password. The screen should look like this:

    Visual Studio 2008 add connection

  12. Now click the “Test Connection” button. You should see this dialog appear:Visual Studio 2008 test connection

    Click the “OK” button.Note: If you get this error message it means that the ODAC client cannot resolve the data source name you specified for your ASP.NET app. Stop the database server. Ensure that you carry out step 4 of the prerequisites and start the database server again.

    Visual Studio 2008 Oracle tns error
  13. Click “Next” 

    Visual Studio 2008 add connection (3)


  14. Click “Next”  to save the connection string for your ASP.NET web site

    Visual Studio 2008 save connection
  15. Now you need to configure a select statement. Select the DEPARTMENTS table from the Names drop down list and click the checkbox beside “*”. Then click the “Next” button.

    Visual Studio 2008 create query for ASP.NET

  16. The “Test Query” dialog box appears with the select statement that you created in the previous step. 

    Visual Studio 2008 test ASP.NET query

  17. Click the “Test Query” button and you will see the results appear

    Visual Studio 2008 query results

    Click the “Finish” button.

  18. When you see the Data Grid View appear please click the “Enable Paging” check box in the Grid View Tasks panel.

    Visual Studio 2008 data grid

  19. Now you will build your ASP.NET web site and run it. First you must build the web site. Navigate to Build->Build Web Site.

    Visual Studio 2008 build website

  20. If the build was successful you should see this screen

    Visual Studio 2008 test website
  21. Now test the web site by running it. Navigate to “Debug->Start Debugging”

    Visual Studio 2008 debug ASP.NET website

  22. When this dialog box appears, click “OK” to change the web.config file to allow debugging

    Visual Studio 2008 enable debug of ASP.NET site
  23. You will see a web brower appear with the results of your query.

    query results on ASP.NET
  24. Congratulations! You just created and ran your first ASP.NET web site application.
About the author
Jose Alfonso Corominas is a consultant specializing in service oriented architectures using the .NET and J2EE frameworks


Slash Costs, Sky-Rocket Productivity and Reduce System Downtime with Expert Oracle Consulting and Training from Smartsoft

Take advantage of our consultants' skills honed to a fine edge over many years with myriad clients in a variety of industries and use their in-depth knowledge and wide experience to maximise the benefits and minimise the costs of your Oracle systems.

Ask us how we can help you reduce costs, boost productivity and eliminate downtime


footer for Oracle page