How To
Integrate an ASP.NET Web Application With Oracle
This tutorial
on using Oracle with Visual Studio and ASP.NET covers the
basics of
database access and data manipulation from Visual C#. Security
considerations
(whilst important) are beyond the scope of this tutorial.
Prerequisites
Install Visual Studio 2008 for
building your application
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 database
4. Install 11g Data Access Components (ODAC) for
Visual Studio 11.1.07.20 or later. If you accepted the default
settings of the installer this is installed in c:\app.
6. Copy listener.ora, sqlnet.ora and tnsnames.ora to
c:\app\product\11.1.0\client_1\Network\Admin to enable the application
to connect to the database and to
prevent a TNS-12514:
TNS: could not resolve the connect
identifier error.
How To Create Your ASP.NET Web Site
Watch the above video and see how to do it in real time.
Start Visual Studio 2008
Select File->New
Web Site from the menu
You will see the list of templates appear on
the "New Web Site" page.
Select the "ASP.NET website" template; Visual C# as the
language and set the location to "c:\MyFirstWebSite"
Click
on the Design tab when you see the “Default.aspx” page in your
new ASP.NET web site. Your screen should look like
this:
Move the mouse over the Toolbox tab to bring up
the Toolbox.
Oracle Tips
& Tricks
to
SKYROCKET Your Career!
If you're not
already a subscriber
to Oracle
Tips & Tricks you're missing out on a
myriad of tips and techniques to help
you become a better, faster, smarter developer. Subscribe now and ignite your
career.
Expand Data and drag
the GridView control to the canvas so that it appears
like this:
Next click the ">"
to bring the GridView Tasks into view
if it is not already and select <New
data source…> from the drop down box.
This starts the Dat Source Configuration Wizard
as shown below. Choose Database as the Data source type, enter
"HR" as the ID and click “OK” to advance to the next screen.
Click on the "New Connection" button to bring
up the Add Connection screen.
On the Add Connection screen, click
on the “Change…” button.
In the Change Data Source
Dialog
box ensure the Data source and the Data provider are set
correctly as shown in the following screen shot. Tick
“Always use this selection” and click
"OK"
Back on the "Add Connection" screen, set the
Data Source Name to “HR.XE” and enter
“HR” for
both the user name and the password fields in the connection details
tab.
Ensure all the details have been
entered/set correctly by
clicking on the "Test
Connection" button. If an error message appears ensure the database is
running, all the details have been entered correctly and that ODAC has
been installed as per step 4 of the pre-requisites. If the test
succeds the following message box will pop up.
Click
the OK button then click Next on the Configure Data Source
screen
and click Next again to save the connection string and advance to
configuring the select statement
To configure the select statement,
select DEPARTMENTS from the
Names drop down list and select “*” from the columns list to
retrieve all columns from the departments table when the query is run.
Then
click the “Next” button to bring up the test query screen.
The
“Test Query” dialog box appears with the select statement that you
created in the previous step. Click the “Test Query” button to
run the query and display the results.
Click "Finish", to display the Data Grid View,
then click the “Enable Paging”
check box in the Grid View Tasks panel.
Navigate to Build->Build
Web Site on the menu to build your ASP.NET web site.
Assuming the build is successful, navigate to
“Debug->Start
Debugging” to run and test your web site.
Enable debugging in the web.config file and
click OK.
This
causes the results of your query to appear in a browser. That's it -
you've succesfully built an ASP.NET web site and connected it to the
database.
Looking for
instructor-led training to learn SQL, PL/SQL,
database administration, Linux/Unix system administration?