Oracle® Database: 11g Release 2 (11.2)
Oracle® Database: 11g Release 2 (11.2)
Oracle® Database: 11g Release 2 (11.2)
August 2009
Oracle Database 2 Day + .NET Developer's Guide, 11g Release 2 (11.2)
E10767-01
Copyright © 2006, 2009, Oracle and/or its affiliates. All rights reserved.
This software and related documentation are provided under a license agreement containing restrictions on
use and disclosure and are protected by intellectual property laws. Except as expressly permitted in your
license agreement or allowed by law, you may not use, copy, reproduce, translate, broadcast, modify, license,
transmit, distribute, exhibit, perform, publish, or display any part, in any form, or by any means. Reverse
engineering, disassembly, or decompilation of this software, unless required by law for interoperability, is
prohibited.
The information contained herein is subject to change without notice and is not warranted to be error-free. If
you find any errors, please report them to us in writing.
If this software or related documentation is delivered to the U.S. Government or anyone licensing it on
behalf of the U.S. Government, the following notice is applicable:
U.S. GOVERNMENT RIGHTS Programs, software, databases, and related documentation and technical data
delivered to U.S. Government customers are "commercial computer software" or "commercial technical data"
pursuant to the applicable Federal Acquisition Regulation and agency-specific supplemental regulations. As
such, the use, duplication, disclosure, modification, and adaptation shall be subject to the restrictions and
license terms set forth in the applicable Government contract, and, to the extent applicable by the terms of
the Government contract, the additional rights set forth in FAR 52.227-19, Commercial Computer Software
License (December 2007). Oracle USA, Inc., 500 Oracle Parkway, Redwood City, CA 94065.
This software is developed for general use in a variety of information management applications. It is not
developed or intended for use in any inherently dangerous applications, including applications which may
create a risk of personal injury. If you use this software in dangerous applications, then you shall be
responsible to take all appropriate fail-safe, backup, redundancy, and other measures to ensure the safe use
of this software. Oracle Corporation and its affiliates disclaim any liability for any damages caused by use of
this software in dangerous applications.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks
of their respective owners.
This software and documentation may provide access to or information on content, products, and services
from third parties. Oracle Corporation and its affiliates are not responsible for and expressly disclaim all
warranties of any kind with respect to third-party content, products, and services. Oracle Corporation and
its affiliates will not be responsible for any loss, costs, or damages incurred due to your access to or use of
third-party content, products, or services.
Contents
1 Introduction
About This Guide..................................................................................................................................... 1-1
What is the Microsoft .NET Framework .............................................................................................. 1-2
Overview of Oracle Data Provider for .NET....................................................................................... 1-2
Overview of Oracle Developer Tools for Visual Studio .................................................................. 1-2
Overview of .NET Stored Procedures .................................................................................................. 1-2
Overview of Oracle Providers for ASP.NET....................................................................................... 1-3
iii
Adding Namespace Directives .............................................................................................................. 3-5
Designing the User Interface ................................................................................................................. 3-7
Writing the Connection Code ............................................................................................................. 3-10
Compiling and Running the Application ........................................................................................ 3-13
Error Handling ....................................................................................................................................... 3-14
Using Try-Catch-Finally Block Structure .................................................................................... 3-15
Handling General Errors................................................................................................................ 3-15
Handling Common Oracle Errors ................................................................................................ 3-16
iv
8 Developing and Deploying .NET Stored Procedures
Overview of .NET Stored Procedures .................................................................................................. 8-1
Starting the Common Language Runtime Service ............................................................................ 8-1
Creating a Connection as SYSDBA....................................................................................................... 8-2
Creating an Oracle Project ...................................................................................................................... 8-4
Creating .NET Stored Functions and Procedures............................................................................... 8-5
Deploying .NET Stored Functions and Procedures........................................................................... 8-7
Running .NET Stored Functions and Procedures ........................................................................... 8-12
Running .NET Stored Procedure in a Query Window................................................................... 8-13
B Copying a Form
Index
v
vi
Preface
Audience
We assume that users of this book have already read the Oracle Database 2 Day DBA
and the Oracle Database 2 Day Developer's Guide, are familiar with basics of SQL and
PL/SQL, and know how to use Microsoft Visual Studio.
Documentation Accessibility
Our goal is to make Oracle products, services, and supporting documentation
accessible to all users, including users that are disabled. To that end, our
documentation includes features that make information available to users of assistive
technology. This documentation is available in HTML format, and contains markup to
facilitate access by the disabled community. Accessibility standards will continue to
evolve over time, and Oracle is actively engaged with other market-leading
technology vendors to address technical obstacles so that our documentation can be
accessible to all of our customers. For more information, visit the Oracle Accessibility
Program Web site at http://www.oracle.com/accessibility/.
vii
Related Documents
For more information, see the following documents in Oracle Database documentation
set:
■ Oracle Data Provider for .NET Developer's Guide
■ Oracle Database Extensions for .NET Developer's Guide
■ Oracle Database 2 Day DBA
■ Oracle Database 2 Day Developer's Guide
■ Oracle Developer Tools for Visual Studio Dynamic Help
■ Oracle Net Services Administrator's Guide
■ Oracle Database Express Edition Installation Guide for Microsoft Windows
Conventions
The following text conventions are used in this document:
Convention Meaning
boldface Boldface type indicates graphical user interface elements associated
with an action, or terms defined in text or the glossary.
italic Italic type indicates book titles, emphasis, or placeholder variables for
which you supply particular values.
monospace Monospace type indicates commands within a paragraph, URLs, code
in examples, text that appears on the screen, or text that you enter.
viii
1
1 Introduction
Note: This guide was created using Microsoft Visual Studio 2008. If
you are using Microsoft Visual Studio 2005, you may notice
differences in screen shots, shortcuts, menu options, and generated
code, but generally the differences should be minor and not cause
problems.
After working through this book, you will be ready to continue with more extensive
information available in the Oracle Database documentation library.
See Also:
■ Visual Studio Dynamic help
■ Oracle Data Provider for .NET Developer's Guide
■ Oracle Database Extensions for .NET Developer's Guide
■ Oracle Database 2 Day DBA
■ Oracle Database 2 Day Developer's Guide
Introduction 1-1
What is the Microsoft .NET Framework
See Also:
■ Chapter 7, "Using ASP.NET with Oracle Database"
■ Oracle Providers for ASP.NET Developer's Guide
Introduction 1-3
Overview of Oracle Providers for ASP.NET
Oracle Database
You must have Oracle Database installed, either locally or on a remote computer.
Note: The samples in this guide all require Oracle Database 11g
client. However, you may use any Oracle Database 9i Release 2 or
higher as they are supported with this client.
If you plan to use Oracle Database Extensions for .NET, then the client
also requires connecting to Oracle Database 11g.
You can administer the database with the user interface, Enterprise Manager, which
can run scripts and queries, and more.
Sample Data
The sample data used in this book is contained in the HR schema, one of the Oracle
Sample Schemas. The Sample Schemas are included as part of the Oracle Database
installation.
See Also: Oracle Database Sample Schemas for the HR data model and
table descriptions
Note: Please note that as new versions of Oracle .NET products are
released, the install process may change slightly from what is shown
in this guide. The screenshots are based on Oracle Data Access
Components (ODAC) version 11.1.0.6.21.
To install:
1. In your Internet browser, navigate to the following location, and download ODAC
with Oracle Developer Tools for Visual Studio:
http://www.oracle.com/technology/software/tech/windows/odpnet/index.html
2. Extract all the files from the zip file to a folder in your file system.
3. Double-click Setup.exe.
Oracle Installer launches. A screen appears briefly to detect required dependencies
and then the Oracle Universal Installer (OUI) Welcome screen appears.
4. Click Next.
The Select a Product to Install screen appears
7. Click Next.
The installer performs prerequisite check. The status for each should be succeeded.
8. Click Next.
The Available Product Components screen appears.
Please be sure that the following are checked:
■ Oracle Data Provider for .NET 2.0
■ Oracle Providers for ASP.NET
■ Oracle Developer Tools for Visual Studio
■ Oracle Instant Client
9. Click Next.
A screen appears reminding you that you must run the SQL scripts located in
ORACLE_BASE\ORACLE_HOME\client_1\ASP.NET\SQL if you wish to use
Oracle Providers for ASP.NET.
Where:
sid: Is the database service name
hostname: Is the database computer name
port: Is the port to use to communicate to the database
address name: Is a user-defined short name for the connect descriptor. This short
name will be used in the connection string of your .NET application.
Example 2–2 shows a sample tnsnames.ora file.
At runtime, the ASP.NET application connects to the database using the database
user's credentials, in the connection string.
To set up the Oracle database, database administrators must grant certain database
privileges to the Oracle Providers for ASP.NET database user schema. With these
privileges, the database user can create the tables, views, stored procedures, and other
database objects that Oracle Providers for ASP.NET require.
After the privileges have been granted, the database user then can run the Oracle
Provider for ASP.NET configuration scripts.
This section walks you step by step through the Oracle Providers for ASP.NET setup
for your database. You do not have to complete this section if you do not plan to
complete the ASP.NET provider portion of this tutorial (second half of Chapter 7). The
Oracle Providers for ASP.NET setup uses Oracle Developer Tools for Visual Studio,
which should be installed before beginning setup.
This step creates the user ASPNET_DB_USER in the database, with the
password that you enter.
c. Run the command by clicking Execute Query (the green arrow at the top left).
The bottom window indicates that the command was successfully completed.
3. Return to the Server Explorer, select SYS.ORCL again, right-click and select
Privileges...
4. Grant privileges to the new database user so it can create the schema and store
web site state for the ASP.NET providers:
■ Set Object type to USER and set User to ASPNET_DB_USER.
■ Use the right angle ( >) arrow in the middle to move privileges from the
Available Privileges list to the Granted Privileges list.
The generally required privileges include:
– Change notification
– Create job
– Create procedure
– Create public synonym
– Create role
– Create session
– Create table
– Create view
– Drop public synonym
– Unlimited Tablespace - This example grants ASPNET_DB_USER unlimited
tablespace. However, in most cases the administrator assigns the database
user a specific tablespace quota.
Click Apply and the output window indicates success. Click OK.
Errors may occur during the setup script execution if the Oracle Providers for
ASP.NET user is not granted the necessary privileges.
3. When the Run SQL*Plus Script screen reappears, select New Connection.
When the Connection Properties screen appears, be sure that the data source is
Oracle Database (Oracle ODP.NET) and the data source name ORCL. Then enter
the User name, ASPNET_DB_USER, and Password, with the Role as Default. Click
OK.
In some situations, the Oracle Server Login dialog may appear. If it does, you can
choose whether or not to Save Password.
4. When Run SQL*Plus Script reappears, select Run.
***********************************************************************************************
The SQL file runs, and in the background, the output window confirms the
success of the scripts.
5. When the scripts finish running, select Cancel.
Table 2–1 Individual Install Scripts for Oracle Providers for ASP.NET
Table 2–1 (Cont.) Individual Install Scripts for Oracle Providers for ASP.NET
Note: Be sure to change the password to the one that you have
created. Also, be sure to remove any carriage returns that you might
have copied into the connection string.
with. Developers can set up their web.config file with the same XML syntax as the
machine.config file.
A solution can contain several projects; when it contains only one project, you can
use the same name for both.
8. Check Create directory for solution.
9. Click OK.
Adding a Reference
This section shows you how to add a reference to the Oracle.DataAccess.dll file,
which contains the data provider, Oracle Data Provider for .NET.
To add a reference:
1. From the Project menu, select Add Reference.
■ Visual Basic:.
Add to the top of the file, in the declarations section.
Imports Oracle.DataAccess.Client
Imports Oracle.DataAccess.Types
3. Save the changes by selecting Save from the File menu, or using the Ctrl+S
keyboard shortcut.
6. From the menu, select Properties, if the Properties Window is not already visible.
The Properties Window appears.
7. In the Properties Window, change the Text property from label1 to User ID.
8. Repeat steps 4 through 7 twice, placing two more labels on Form 1 and changing
their text properties to Password and Data Source.
9. In the Toolbox, select TextBox, and drag it onto the Form1, next to the User ID
label.
11. Repeat steps 9 and 10 twice, positioning two more text boxes next to the existing
labels, and setting the Name property to password and dataSource.
12. Select the text box next to the Password label. In the Properties Window, scroll to
the PasswordChar property and set it to an asterisk (*).
This masks the password during entry.
13. From the Toolbox, select Button and drag it onto Form1.
In the Properties Window, change the Text property of the button from button1 to
Connect, and change the Name property to connect.
14. Save.
Visual Basic: Add the conn class variable in the Form1 class declaration, using
this code.
Public Class Form1
Dim conn As New OracleConnection
***********************************************************************************************
3. Save your changes.
4. Change to Designer view by clicking on the View menu and selecting Designer.
5. Double-click the Connect button on Form1 to open the code window to the
connect_Click() method.
Insert the code indicated into the connect_Click() method.
Visual C#:
conn.ConnectionString = "User Id=" + userID.Text +
";Password=" + password.Text +
";Data Source=" + dataSource.Text + ";";
conn.Open();
Visual Basic:
conn.ConnectionString = "User Id=" + userID.Text & _
";Password=" + password.Text & _
";Data Source=" + dataSource.Text
conn.Open()
Note: Before a connection can be opened, it must be built from user input for the
User ID, Password, and Data Source. The Open() method makes the actual
connection.
6. Set the Enabled attribute of the button to false by inserting the indicated code
at the end of the connect_Click() method.
This disables the Connect button, which is a good practice once a connection is
successfully made.
Visual C#:
connect.Enabled = false;
Visual Basic:
connect.Enabled = false
You have now finished writing an application that can connect to the Oracle database.
The following sections show how to use it.
2. Ensure that there are no errors reported in the output window, available from the
View menu.
The following graphics shows a typical output result.
3. If there are any errors indicated, from the View menu, select Error List and fix the
errors.
4. From the Debug menu, select Start Without Debugging to run the application.
5. In the Form1 application, enter the User ID, Password, and Data Source.
Click Connect.
This is where the application makes use of the tnsnames.ora file. See
"Configuring a NET Connect Alias" on page 2-7.
Once the connection is opened, the Connect button is disabled. You have
succeeded in implementing a connection to an Oracle Database instance.
Error Handling
Applications must be able to handle run-time errors gracefully. For example, if you try
to log in using an incorrect password, the application you developed so far cannot
establish a connection to the database, and exits with the following unhandled
exception error, ORA-1017: invalid username/password, logon denied.
You must reselect Start Without Debugging to try this with a different password.
Error handling manages occurrences of conditions that change the normal flow of
program execution. Oracle Data Provider for .NET contains three classes for error
handling and support:
■ The OracleError class represents a warning or an error reported by Oracle.
■ An OracleErrorCollection class represents a collection of all errors that are
thrown by the Oracle Data Provider for .NET. It is a simple ArrayList that holds
a list of OracleErrors.
■ The OracleException class represents an exception that is thrown when the
Oracle Data Provider for .NET encounters an error. Each OracleException
object contains at least one OracleError object in the Error property that
describes the error or warning.
{
conn.Dispose();
}
}
Alternatively, you can use C# syntax that disposes of a connection when it goes
out of scope, with the using keyword, as follows:
using (OracleConnection conn = new OracleConnection())
{
conn.Open();
// application code
...
}
Visual Basic:
Try
conn.Open()
connect.Enabled = false
Catch ex As Exception
MessageBox.Show(ex.Message.ToString())
Finally
conn.Dispose()
End Try
2. Add the Catch OracleException block shown below in bold, before the Catch
Exception block previously added in the connect_Click() method.
Visual C#:
try
{
conn.Open();
connect.Enabled = false;
}
catch (OracleException ex)
{
switch (ex.Number)
{
case 1:
MessageBox.Show("Error attempting to insert duplicate data.");
break;
case 12560:
MessageBox.Show("The database is unavailable.");
break;
default:
MessageBox.Show("Database error: " + ex.Message.ToString());
break;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
finally
{
conn.Dispose();
}
}
Visual Basic:
Try
conn.Open()
connect.Enabled = false
Catch ex As Exception
MessageBox.Show(ex.Message.ToString())
Finally
conn.Dispose()
End Try
3. Compile and run the application again, as described in section "Compiling and
Running the Application" on page 3-13.
Note that the ORA-12560 error appears in the pop-up window as The database
is unavailable with no error number provided.
Retrieving and Updating with Oracle Data Provider for .NET 4-1
Retrieving Data: a Simple Query
conn.Open();
connect.Enabled = false;
// SQL Statement
string sql = "select department_name from departments"
+ " where department_id = 10";
}
Visual Basic:
Try
conn.Open()
connect.Enabled = False
4. Use the new sql variable to create the OracleCommand object, and set the
CommandType property to run a text command.
Visual C#:
try
{
conn.Open();
connect.Enabled = false;
// SQL Statement
string sql = "select department_name from departments"
+ " where department_id = 10";
Visual Basic:
Try
conn.Open()
connect.Enabled = False
To retrieve data:
1. Create an OracleDataReader object, by adding the code indicated to the bottom
of the Try block of the connect_Click() method.
This enables you to read the result of the query.
Visual C#:
OracleDataReader dr = cmd.ExecuteReader();
dr.Read();
Visual Basic:
Dim dr As OracleDataReader = cmd.ExecuteReader()
dr.Read()
2. Open Form1 in Design view. From the View menu, select Designer.
3. From the View menu, select Toolbox.
4. From the Toolbox, select a Label and drag it onto Form1.
5. From the View menu, select Properties Window.
6. In the Properties window, change the Text of the label to Department.
7. From the Toolbox, under Window forms, select a ListBox and drag it onto Form1.
8. In the Properties window, under Design, change the Name to departments.
9. Add accessor type methods for retrieving data from the query result.
Double-click the connect button to edit the connect_click() method, and add
the code indicated to the bottom of the try block.
Visual C#:
departments.Items.Add(dr.GetString(0));
Visual Basic:
departments.Items.Add(dr.GetString(0))
Typed accessors, such as GetString, return native .NET data types and native
Oracle data types. Zero-based ordinals passed to the accessors specify which
column in the result set to return.
10. Build and save the application.
11. Run the application. Enter the login and data source.
Retrieving and Updating with Oracle Data Provider for .NET 4-3
Retrieving Data: Bind Variables
After you connect, the departments list box shows Administration, the
correct name for department number 10 in the HR schema, as requested by the
SELECT statement.
The following code replaces the numerical value with a bind variable :department_
id. A bind variable identifier always begins with a single colon ( :).
SELECT department_name FROM departments WHERE department_id = :department_id
Note that bind variables can also be used with UPDATE, INSERT, and DELETE
statements, and also with stored procedures. The following code illustrates how to use
bind variables in an UPDATE statement:
UPDATE departments SET department_name = :department_name
WHERE departname_id = : department_id
See "Inserting, Deleting, and Updating Data" on page 4-12 for more details.
You can use the OracleParameter class to represent each bind variable in your .NET
code. The OracleParameterCollection class contains the OracleParameter
objects associated with the OracleCommand object for each statement. The
OracleCommand class passes your SQL statement to the database and returns the
results to your application.
You can bind variables by position or by name by setting the OracleCommand
property BindByName (which defaults to false).
■ Binding by position
You must use the Add() method to add the parameters to the
OracleParameterCollection in the same order as they appear in the SQL
statement or stored procedure.
■ Bind by name
You may add the parameters to the collection in any order; however, you must set
the ParameterName property for the parameter object to the same name as the
bind variable identifier in the stored procedure declaration.
In addition to the binding mode (by position or by name), the .NET developer sets the
following properties for each parameter object: Direction, OracleDbType, Size,
and Value.
■ Direction Bind variables may be used as output, input, or input/output
parameters. The Direction property indicates the direction of each parameter.
The default value of the Direction property is Input.
■ OracleDbType property indicates whether or not the parameter is a number, a
date, a VARCHAR2, and so on.
■ Size indicates the maximum data size that parameters with a variable length data
type, such as VARCHAR2, can hold.
■ Value contains the parameter value, either before statement execution (for input
parameters), after execution (for output parameters), or both before and after (for
input/output parameters).
6. Change the SELECT statement to use the bind variable by adding the code
indicated to the Try block of the connect_Click() method.
Changed or new code is in bold typeface.
Visual C#:
string sql = "select department_name from departments where department_id = " +
":department_id";
OracleCommand cmd = new OracleCommand(sql, conn);
cmd.CommandType = CommandType.Text;
OracleParameter p_department_id = new OracleParameter();
p_department_id.OracleDbType = OracleDbType.Decimal;
p_department_id.Value = departmentID.Text;
cmd.Parameters.Add(p_department_id);
Retrieving and Updating with Oracle Data Provider for .NET 4-5
Retrieving Data: Multiple Values
OracleDataReader dr = cmd.ExecuteReader();
dr.Read();
departments.Items.Add(dr.GetString(0));
Visual Basic:
Dim sql As String = "select department_name from departments where" & _
"department_id= ":department_id"
Dim cmd As OracleCommand = New OracleCommand(sql, conn)
cmd.CommandType = CommandType.Text
Dim p_department_id as OracleParameter = new OracleParameter()
p_department_id.OracleDbType = OracleDbType.Decimal
p_department_id.Value = departmentID.Text
cmd.Parameters.Add(p_department_id)
departments.Items.Add(dr.GetString(0))
For this code, the parameter object sets the OracleDbType property, but there is
no need to set the Direction property because it uses the default value, Input.
There is no need to set the Size property because the object is an input parameter,
and the data provider can determine the size from the value.
7. Save and run the application.
8. Enter the login information, and a typical department number, such as 50, from
the HR schema.
9. Click Connect.
The application returns the name of the department that corresponds to the
department ID.
Processing multiple rows from the DataReader object requires a looping construct.
Also, a control that can display multiple rows is useful. Because the
OracleDataReader object is a forward-only, read-only cursor, it cannot be bound to
an updatable or backward scrollable control such as Windows Forms DataGrid
control. An OracleDataReader object is, however, compatible with a ListBox
control.
Visual Basic:
Try
...
Dim sql As String = "select department_name from departments " & _
"where department_id < :department_id"
...
While (dr.Read())
departments.Items.Add(dr.GetString(0))
End While
Retrieving and Updating with Oracle Data Provider for .NET 4-7
Using the DataSet Class with Oracle Data Provider for .NET
Using the DataSet Class with Oracle Data Provider for .NET
The DataSet class provides a memory-resident copy of database data. It consists of
one or more tables that store relational or XML data. Unlike an OracleDataReader
object, a DataSet is updatable and backward scrollable.
Visual Basic:
da = new OracleDataAdapter(cmd);
cb = new OracleCommandBuilder(da);
ds = new DataSet();
da.Fill(ds);
departments.DataSource = ds.Tables[0];
Visual Basic:
conn.Open()
connect.Enabled = False
Dim sql As String = "select * from departments where department_id < 60"
cmd = New OracleCommand(sql, conn)
cmd.CommandType = CommandType.Text
da = New OracleDataAdapter(cmd)
cb = New OracleCommandBuilder(da)
ds = New DataSet()
da.Fill(ds)
departments.DataSource = ds.Tables(0)
11. Run the application, entering the login and data source.
After you successfully connect to the database, the data grid is populated with the
results of the query.
Retrieving and Updating with Oracle Data Provider for .NET 4-9
Enabling Updates to the Database
.
***********************************************************************************************
Visual C#:
da.Update(ds.Tables[0]);
Visual Basic:
da.Update(ds.Tables(0))
You may see some errors show up in the Error List. These will disappear after you
add the code in the next step.
6. Within the Form() method or Form1_Load method, add the code indicated.
Visual C#:
public Form1()
{
InitializeComponent();
save.Enabled = false;
}
Visual Basic:
Private Sub Form1_Load(ByVal sender As System.Object, & _
ByVal e As System.EventArgs) Handles MyBase.Load
save.Enabled = false
7. Within the connect_Click() method try block, add code to enable the Save
button as indicated:
Visual C#:
conn.Open();
...
departments.DataSource = ds.Tables[0];
save.Enabled = true;
Visual Basic:
conn.Open()
...
departments.DataSource = ds.Tables(0)
save.Enabled = True
8. Remove the conn.Dispose() call from the finally block in the connect_
Click() method.
Note: In the previous code used in this example, this method was necessary to
dispose or close the connection. However, with these changes to the code, it is
necessary to keep the connection open after the query result returns, so that data
changes made by the end user are propagated to the database. A general override
call, components.Dispose(), is already part of the definition of Form1.
9. Build and save the application.
10. Run the application, entering the login and data source.
After you successfully connect to the database, the data grid is populated with the
results of the query.
Retrieving and Updating with Oracle Data Provider for .NET 4-11
Inserting, Deleting, and Updating Data
3. Click Save.
4. Close the application to check if the new record is saved.
5. Run the application again, and connect to the database.
Note that the new department is at the top of the DEPARTMENTS table, in
numerical order by DEPARTMENT_ID.
6. Change the name of the department to Community Volunteers, and click the
Save button.
7. Repeat Step 4, run the application again, and connect to the database, and note
that the name of the department is changed.
8. Select the entire record you just changed (click the cursor icon in the far left
column), and delete it using the Delete key. Click the Save button.
9. Repeat Step 4, run the application again, and connect to the database, and note
that the new record is no longer part of the DEPARTMENTS table.
10. Close the application.
Retrieving and Updating with Oracle Data Provider for .NET 4-13
Inserting, Deleting, and Updating Data
4. When the Add Connection window appears, determine if the Data source says
Oracle Database (Oracle ODP.NET).
If it does, skip to Step 6.
If Data source does not say Oracle Database (Oracle ODP.NET), select Change.
The Change Data Source window appears.
5. Choose Oracle Database and then select Oracle Data Provider for .NET.
6. On the Connection Details tab, in the Add Connection window, enter the
following information:
Data source name: For this example, use the alias of the remote database instance,
orcl.
If you are connecting to a database on the same computer, use the Local
Database.
Select the Use a specific user name and password option.
7. Click the Apply Filters tab, and verify that the HR schema is in the Displayed
schemas column. When you expand the schema category nodes in the data
connection, only those schema objects (tables, views, and so on) selected in the
Apply Filters tab appear.
To create a table:
1. In Server Explorer, right-click Tables and select New Relational Table.
3. In the Column Properties tab, add the following six columns in this manner:
Click Add. Then enter the new column information. Keep clicking add until you
have added all the new columns.
Fields may differ depending on the data type. You might have to close windows
such as Server Explorer or Solution Explorer to access the entire tab.
■ Name LAST_NAME, Data Type VARCHAR2, and Size 30. Leave all other
properties at their default values.
■ Name FIRST_NAME, Data Type VARCHAR2, and Size 20. Leave all other
properties at their default values.
■ Name BIRTH_DATE, Data Type DATE. Leave all other properties at their
default values.
■ Name RELATIONSHIP, Data Type VARCHAR2, and Size 20. Leave all other
properties at their default values.
■ Name EMPLOYEE_ID, Data Type NUMBER, deselect Allow null, enter
Precision 6 and Scale 0.
■ Name DEPENDENT_ID, Data Type NUMBER, deselect Allow null check box,
enter Precision 6 and Scale 0.
To create an index:
1. In the DEPENDENTS Table Design view, click the Indexes tab.
This action creates the two new constraints on the DEPENDENTS table in the HR
schema. To see the Server Explorer, expand the hierarchy tree for the table
DEPENDENTS and constraints.
To populate a table:
1. In Server Explorer, right-click the DEPENDENTS table and select Retrieve Data.
Note that the data is automatically saved as you move between rows.
9. Under Save the Connection String to the Application Configuration File, select
Yes, save the connection as: ConnectionString.
Click Next.
See Also: "Using the DataSet Class with Oracle Data Provider for
.NET" on page 4-8 for information about the DataSet Class
Note that along with the table grid (which includes record navigation elements),
the following components were added to the design view of your project. These
objects represent automatically generated code for Form1.
Visual C#:
tableDependents, dEPENDENTSBindingSource,
dEPENDENTSTableAdapter, tableAdapterManager, and
dEPENDENTSBindingNavigator
Visual Basic:
TableDependents, DEPENDENTSBindingSource,
DEPENDENTSTableAdapter, TableAdapterManager, and
DEPENDENTSBiningNavigator
4. Double-click the Save icon (floppy disk) near the top of Form1.
This opens the code window for the Save icon for Form1.
5. In the private method, xxxSaveItem_Click(), encapsulate the existing code in
a try...catch block. See the code listed for the complete Visual C# and Visual
Basic names of this automatically generated method.
Also, add a MessageBox.show() call to both the try and catch sections. The
updated method code follows, with new or changed code in bold font.
Visual C#:
private void dEPENDENTSBindingNavigatorSaveItem_Click(object sender, EventArgs
e)
{
try
{
this.Validate();
this.dEPENDENTSBindingSource.EndEdit();
this.tableAdapterManager.UpdateAll(this.tableDependents);
MessageBox.Show("Update successful");
}
catch (System.Exception ex)
{
MessageBox.Show("Update failed: "+ ex.Message.ToString());
}
}
Visual Basic#:
Private Sub DEPENDENTSBindingNavigatorSaveItem_Click(
ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles DEPENDENTSBindingNavigatorSaveItem.Click
Try
Me.Validate()
Me.DEPENDENTSBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.TableDependents)
MessageBox.Show("Update successful")
Catch ex As Exception
MessageBox.Show("Update failed: " + ex.Message.ToString())
End Try
End Sub
6. To compile and run the application, follow the instructions in section "Compiling
and Running the Application" on page 3-13.
You can test the new application in the following manner. The floppy disk icon
represents the Save command.
If you have not previously saved the password, the Oracle Server Login opens and
you can enter the password now. If you have saved the password, then the
connection expands immediately.
***********************************************************************************************
7. Click OK when you finish adding parameters.
The New Package window reappears.
8. In the New Package window, click Preview SQL to see the SQL code created.
A Preview SQL window appears, containing code similar to the following. Note
that this code has been abbreviated by removing most of the comments.
CREATE PACKAGE "HR"."HR_DATA" IS
PROCEDURE "GETCURSORS" (
"DEP_ID" IN NUMBER,
"EMPLOYEES_C" OUT SYS_REFCURSOR,
"DEPENDENTS_C" OUT SYS_REFCURSOR);
END "HR_DATA";
-- Make private declarations of types and items, that are not accessible
-- outside the package
PROCEDURE "GETCURSORS" (
"DEP_ID" IN NUMBER,
"EMPLOYEES_C" OUT SYS_REFCURSOR,
"DEPENDENTS_C" OUT SYS_REFCURSOR) IS
NULL;
END "GETCURSORS";
END "HR_DATA";
14. To run the stored procedure, in Server Explorer, expand the HR_DATA package.
Right-click the GETCURSORS method, and select Run.
Under this message, note two output parameters (together with DEP_ID):
EMPLOYEES_C and DEPENDENTS_C.
17. Select the Value column entry for EMPLOYEES_C.
The Parameter Details area appears, showing the employees in department 60. The
value for DEP_ID is 60.
2. Make a copy of Form3.xx, which you finished at the end of Chapter 4 and name
it Form4.xx, following the instructions in Appendix B, "Copying a Form".
3. With Form1 selected, switch to code view.
4. In the try block of the connect_Click() method, replace the two command
assignment lines, starting with cmd = New OracleCommand... with the code
indicated.
Visual C#:
cmd = new OracleCommand("HR_DATA.GETCURSORS", conn);
cmd.CommandType = CommandType.StoredProcedure;
Visual Basic:
cmd = new OracleCommand("HR_DATA.GETCURSORS", conn)
cmd.CommandType = CommandType.StoredProcedure
5. Under the code added in Step 3, add definitions and bindings for the three
parameters of the GETCURSORS stored procedure as OracleParameter objects,
calling them dep_id, employees_c and dependents_c.
Visual C#:
OracleParameter dep_id = new OracleParameter();
dep_id.OracleDbType = OracleDbType.Decimal;
dep_id.Direction = ParameterDirection.Input;
dep_id.Value = 60;
cmd.Parameters.Add(dep_id);
Visual Basic:
Dim dep_id As OracleParameter = New OracleParameter
dep_id.OracleDbType = OracleDbType.Decimal
dep_id.Direction = ParameterDirection.Input
dep_id.Value = 60
cmd.Parameters.Add(dep_id)
Note that the DataGrid contains the first result set from the stored procedure,
which matches the query of the EMPLOYEES table.
3. From New Web Site, select ASP.NET Web Site and enter or browse to the
directory location for the web site. Click OK.
4. In the Default.aspx tab, click the Design icon at the bottom of the screen.
5. In the <div> element, which appears as a dotted rectangle, enter a title, such as
Employees List.
7. Expand the Data group and drag the GridView control into the dotted rectangle
labeled <div> of the Designer
8. When a grid with dummy titles and contents appears, view the GridView Tasks
list on the right.
If you do not see the task list, select the grid, and then click the > symbol on the
right.
1. Under the GridView Tasks, select <New data source...> from the Choose Data
Source list, as shown in step 8 in the previous section.
A Data Source Configuration wizard starts.
2. Select Database. Enter HR as the ID for the data source. Click OK.
3. Click the down arrow to choose HR.ORCL from the list. Click Next.
4. Click Next to save the connection string in the application configuration file.
5. Select the EMPLOYEES table from the Name list. In the Columns list, check the box
next to the asterisk ( *).
These selections tell Oracle to return all the rows from the EMPLOYEES table, just
as if you had typed SELECT * FROM EMPLOYEES.
Click Next.
8. From the GridView Tasks, select Enable Paging. If you do not see the task list,
select the grid, and then click the > symbol on the right. You may have to scroll
right.
9. From the View menu, select Solution Explorer, and then select the web site.
Right-click and select Build Web Site. The status bar will indicate success or
failure.
10. From the View menu, select Debug, then Start Without Debugging.
A browser window, such as the following, appears, showing the data requested by
the query. You can page through the results using the numbers at the lower left
section of the page.
4. Select Web Form, enter the name login.aspx and click Add.
:
***********************************************************************************************
This is a standard ASP.NET login control, which can retrieve and verify user login
credentials stored in the Oracle database.
7. Right-click the login control and select Properties. For DestinationPageUrl,
select or enter Default.aspx.
When a user successfully logs in, that user will be directed to the Default.aspx
page, which contains the employee data. If a user does not successfully log in, they
will be redirected back to the login page.
Enabling Oracle Providers for ASP.NET and Creating a Lightweight Web User
In this section, you will use the ASP.NET Web Site Administration Tool to do the
following:
■ Direct the web site to use the Oracle ASP.NET providers.
■ Create a new web user specific to this web site, demonstrating the authentication
features added to the site in "Enabling a Web Site for Authentication" on page 7-11.
To direct the web site to use the Oracle ASP.NET providers and create new web site
users, do the following:
1. In Visual Studio, select Website, then ASP.NET Configuration.
2. When the ASP.NET Web Site Administration Tool appears, select the Provider tab.
3. On the Provider page, select the second link: Select a different provider for each
feature (advanced).
4. When the Provider page reappears, change the Membership Provider and Role
Provider to the Oracle versions, if they are not selected.
5. Go to the Security tab and under Users, click Select authentication type.
By default, the ASP.NET site uses Windows authentication to identify users. You
are building a web site that will identify users by their site-specific logins and
passwords. Therefore, the site must be configured to expect to use logins and
passwords.
6. When the Security page reappears, choose From the internet and click Done.
7. When the security tab reappears with new links under Users, choose Create user.
8. In the Create User section, enter the information for the user that you are allowing
to enter the web site, as shown. Enter a password that contains at least 7
characters, including one non-alphanumeric character.
Click Create User.
9. When the Security page reappears, indicating that your account has been
successfully completed, click the Security tab.
Note: Other options for this screen include continuing to create other users or
going to a different tab.
10. When the main Security page reappears, under Access Rules, select Manage
access rules.
By default, anonymous access to the web site is enabled. The above settings secure
the web site by disabling anonymous access. Now, only authenticated users can
view the employee data.
13. The Security page now indicates that the web site denies anonymous users access
to the site.
Click Done.
1. From the Debug menu, select Start Without Debugging, and when the login web
page appears, change the URL to end with Default.aspx rather than
login.aspx and press the enter key.
You are denied access and redirected back to the login page. This shows that
anonymous users cannot browse the web site; only users with credentials have
access.
If you are experimenting with the authentication mechanism, you will likely
repeat this step or try variations. For each variation, either start a new browser or
clear the browser cache. Because browsers cache web pages, if you access
Default.aspx again, you may see the cached version of this web page. This is
not the intended behavior, rather the web page should undergo the ASP.NET
provider authentication process, which is accomplished by using a new browser
instance or clearing the browser cache.
2. Remove the text of the URL after login.aspx. This returns the URL back to the
original state when you first accessed the site.
Enter the User Name Bob and a password that contains at least 7 characters, one of
which is non-alphanumeric.
Click Log In.
The page reappears with the message "Your login attempt was not successful.
Please try again."
Bob is not an authorized user. The web site correctly denies access to the user.
3. Enter the user name Anne, but with an incorrect password for that web site user.
Click Log In.
As the screen shot indicates, the user is denied access, demonstrating that the
control could not verify this user’s credentials with those stored by the Oracle
Membership Provider.
4. Enter the correct password for the web site user.
Click Log In.
The employee data appears. This demonstrates that only authorized users can
access the data. Thus, Oracle Providers for ASP.NET provided web site security in
a very simple manner.
You have now built a data-driven ASP.NET web application. It performs
authentication and retrieves employee data from the database.
If Data source does not say Oracle Database (Oracle ODP.NET), select Change.
The Change Data Source window appears.
5. Choose Oracle Database and then select Oracle Data Provider for .NET.
6. In the Add Connection window, use the following:
■ For User name, enter sys.
■ For Password, enter the password set by the administrator who unlocked and
set up the sys account.
To use the Enterprise Manager to set the sys account password, see About
Administrative Accounts and Privileges in the Oracle Database 2 Day DBA.
■ Ensure that the Role is set to Sysdba.
The Connection name is generated automatically from the Data source name
and the User name values.
4. Click OK.
2. Add these namespace directives for the specific language, as described in "Adding
Namespace Directives" on page 3-5.
Visual C#:
using Oracle.DataAccess.Client;
using Oracle.DataAccess.Types;
Visual Basic:
Imports Oracle.DataAccess.Client
Imports Oracle.DataAccess.Types
while(rdr.Read())
department_id=rdr.GetInt32(0);
rdr.Close();
cmd.Dispose();
Visual Basic:
Public Shared Function getDepartmentno(ByVal employee_id As Integer) As Integer
Dim department_id As Integer = 0
While rdr.Read()
department_id = rdr.GetInt32(0)
End While
rdr.Close()
cmd.Dispose()
End Function
5. Save Class1.
6. From the Build menu, select Build Solution.
7. Check that the Output window indicates a successful build and close it.
.
***********************************************************************************************
An Oracle Deployment Wizard for .NET window appears.
2. In the Oracle Deployment Wizard for .NET window, click Next.
***********************************************************************************************
3. On the Configure your OracleConnection window, click Next.
4. On the Specify your deployment option window, ensure that the first option, Copy
assembly and generate stored procedures is selected, and click Next.
5. On the Specify an assembly and library name window, accept the defaults and
click Next.
6. On the Specify copy options window, accept the defaults and click Next.
Visual Basic:
If you are using Visual Basic, the Microsoft.VisualBasic assembly also
appears as a referenced assembly.
7. On the Specify methods and security details window, under Available methods,
expand HR_DeployStored_CS or HR_DeployStored_VB, then expand Class1,
and select the getDepartmentno() method.
Under Method Details, select HR from the Schema list.
Click Next.
3. Note that the return value for department is 90, indicating that EMPLOYEE_ID
100 is in department 90.
See Also:
■ Chapter 8, "Oracle Data Provider for .NET Globalization Classes"
in Oracle Data Provider for .NET Developer's Guide
■ "Working in a Global Environment" in the Oracle Database 2 Day
Developer's Guide
■ Microsoft .NET Internationalization Internet site,
http://msdn.microsoft.com/en-us/goglobal/bb688096
.aspx
Connecting to SQL*Plus
Several of the following examples require that you use SQL*Plus to connect as a user
with database administrator privileges such as SYS or SYSTEM.
where passwd is the Sys password that was established when the database was
installed. The password does not appear when you type the characters.
or
select * from v$nls_parameters where parameter = 'NLS_LANGUAGE';
Note that you must use hr.employees in order to access the employees table in
the hr schema because you are currently logged in as sys, not hr.
The result of the query returns in the American format specified in Step 1.
The result of the query returns in the American format specified in Step 1.
The result of the query returns in the binary sort specified in Step 1.
The result of the query return the error message in the language specified in Step
1.
5. Reset your language, local, and sort settings back to their original values.
class ClientGlobalizationSample
{
static void Main()
{
OracleGlobalization ClientGlob = OracleGlobalization.GetClientInfo();
Console.WriteLine("Client machine language: " + ClientGlob.Language);
Console.WriteLine("Client characterset: " + ClientGlob.ClientCharacterSet);
}
}
Visual Basic:
Imports System
Imports Oracle.DataAccess.Client
Class ClientGlobalizationSample
Shared Sub Main()
Dim ClientGlob As OracleGlobalization = OracleGlobalization.GetClientInfo()
Console.WriteLine("Client machine language: " + ClientGlob.Language)
Console.WriteLine("Client characterset: " + ClientGlob.ClientCharacterSet)
End Sub
End Class
2. Make a copy of Form3.xx, which you finished at the end of Chapter 4 and name
it Form5.xx, following the instructions in Appendix B, "Copying a Form".
3. Open Form1 of the project, and switch to design view.
4. From the View menu, select Toolbox.
5. From the Toolbox, under Windows Forms, drag and drop a Button onto Form1.
6. Right-click the new Button, select Properties. The Properties window appears.
7. In the Properties window, set these properties:
■ Under Appearance, change Text to Change Date Format.
■ Under Design, change (Name) to date_change.
Form1 should look much like this:
In the properties window, if you click Events (lightning bolt icon), date_change_
Click() now shows as the Event for the date button.
8. Open the new date_change_Click() method just created and add the
following code to change the date format from the standard DD-MON-RR to
YYYY-MM-DD and to update the DataSet.
Visual C#:
si.DateFormat = "YYYY-MM-DD";
conn.SetSessionInfo(si);
ds.Clear();
da.Fill(ds);
departments.DataSource = ds.Tables[0];
Visual Basic:
si.DateFormat = "YYYY-MM-DD"
conn.SetSessionInfo(si)
ds.Clear()
da.Fill(ds)
departments.DataSource = ds.Tables(0)
Note that the ds.Clear() call will clear the old results before posting the
changed data.
Also, the si class variable will be declared and session globalization information
retrieved in Step 10 and Step 11.
9. Within the appropriate method, add the code indicated.
Visual C#: In the Form1() method
date_change.Enabled = false;
10. Add the following class variable to the existing Form1 class declarations right after
the public Form1() block with this code as indicated.
Visual C#:
private OracleGlobalization si;
Visual Basic:
private si As OracleGlobalization
11. Within the connect_Click() method try block, add the indicated code which
does the following:
■ Retrieve the value of the OracleGlobalization object.
■ Retrieve data from the EMPLOYEES table (note the new query).
■ Enable the Change Date Format button.
The changed code is in bold typeface.
Visual C#:
conn.Open();
connect.Enabled = false;
si = conn.GetSessionInfo();
da = new OracleDataAdapter(cmd);
cb = new OracleCommandBuilder(da);
ds = new DataSet();
da.Fill(ds);
departments.DataSource = ds.Tables[0];
save.Enabled = true;
date_change.Enabled = true;
Visual Basic:
conn.Open()
connect.Enabled = false
si = conn.GetSessionInfo()
da = new OracleDataAdapter(cmd)
cb = new OracleCommandBuilder(da)
ds = new DataSet()
da.Fill(ds)
departments.DataSource = ds.Tables[0]
save.Enabled = true
date_change.Enabled = true
Note that the date format changed from the original DD-MON-RR to YYYY-MM-DD.
15. Close the application.
Because you will be using this application to learn about various aspects of application
development with Oracle, you should make copies of your form for reuse.
Index-1
creating a user, 2-9 F
creating a web site, 7-2
creating a web user, 7-13 FCL (Framework Class Libraries), 1-2
creating an Oracle Project, 8-4 File menu, 3-1, 3-2
cultural conventions, 9-1 finally block, 4-8
Culture parameter (ID), 9-7 foreign key, 5-10
CultureInfo object, 9-1 Form1, 3-3
culture-sensitive data, 9-8 form1.cs, 3-3
CurrentCulture parameter, 9-13 form1.vb, 3-3
customizing Oracle Providers for ASP.NET, 2-16 forms, 3-7
Framework Class Libraries (FCL)
definition, 1-2
D
data entry control, 3-7 G
data grid, 6-9
GetSessionInfo() method, 9-9
data provider, 3-4
GetThreadInfo() method, 9-13
Oracle Data Provider for .NET, 1-2
global applications
Data Source Configuration wizard, 7-5
development, 9-1
data source names, 5-1, 8-2
introduction, 9-1
database error messages, 3-16
.NET framework, 9-1
DataGrid class, 6-9
globalization
DataGrid control, 4-6
definition, 9-1
DataReader class, 4-6
session information, 9-9
DataSet class, 4-8
globalization support
updating, 9-9
client, 9-8
date formats, 9-2
ODP for .NET, 9-8
change, 9-9
granting privileges, 2-9
default roles, 5-1
Grant/Revoke Privileges Wizard in ODT, 2-9
Default.aspx, 7-11
GridView control, 7-2
deleting data, 4-12
Design view, 5-5
Designer, 3-7 H
Designer and Code toggle, 3-7
HR schema, 2-1
designing user interfaces, 3-7
dialog
new projects, 3-1 I
Direction property, 4-4 Imports statement, 3-5
display schema, 5-1, 8-2 indexes
Dispose() method, 3-15 add, 5-8
documentation library, 1-1 creating, 5-8
properties, 5-8
E Indexes tab, 5-8
inserting data, 4-12
enabling a web site for authentication, 7-11
InstallOracleASPNETCommon.sql,
enabling Oracle Providers for ASP.NET, 7-13
configuration, 2-8
Enterprise Manager, 2-1, 8-7
error handling
exceptions with ODP.NET, 3-14 L
ODP.NET, 3-14 Label control, 3-7
Oracle, 3-14 linguistic sorts, 9-5
Try-Catch-Finally, 3-15 ListBox, 4-2
error messages, 9-6 local user conventions, 9-2
Error property, 3-14 locale
events awareness, 9-1
click, 4-8 characteristics, 9-1
examples definition, 9-1
names of, 3-3 synchronizing, 9-7
Exception class, 3-16 localization
ExecuteReader() method, 4-2 resources, 9-1
lock, 5-1, 8-2
Index-2
login.aspx, 7-11 Oracle Data Provider for .NET, 2-1
using, 4-1
Oracle Data Provider for .NET (ODP.NET)
M
definition, 1-2
machine.config, 2-8 globalization, 9-1
memory location, 6-2 installation, 2-2
menus Oracle Database, 2-1
File, 3-1, 3-2 documentation library, 1-1
View, 3-7 installation, 2-1
method parameters Oracle Database Extensions for .NET
binding, 6-9 installing, 2-2
definition, 6-9 upgrades, 2-2
methods Oracle date formats, 9-2
Add(), 4-4 Oracle Deployment Wizard for .NET, 1-3, 8-7
Dispose(), 3-15 Oracle Developer Tools
Open(), 3-10 definition, 1-2
Microsoft internationalization features
URL, 9-1 designer, 1-2
Microsoft .NET Framework drag and drop, 1-2
definition, 1-2 dynamic help, 1-2
Microsoft Visual Studio, 1-3 Oracle Data Window, 1-2
2005, 1-1 Oracle Query Window, 1-2
2008, 1-1 PL/SQL editor, 1-2
wizard, 1-2
N installation, 2-2
using, 5-1
name of code files, 3-3 Oracle error messages, 9-6
name of forms, 3-3 Oracle linguistic sorts, 9-5
Name property, 3-7 Oracle number formats, 9-4
namespace directives, 3-5 Oracle Projects
.NET assembly, 1-3 creating, 8-4
NET connect, 2-7 Oracle Providers for ASP.NET, 2-12
.NET languages, 1-2 configuring individually, 2-15
.NET stored functions and procedures customizing, 2-16
creating, 8-5 enabling, 7-13
deploying, 8-7 setup, 2-8
running, 8-12 Oracle Universal Installer (OUI), 2-2
.NET stored procedure, 1-3 ORACLE_BASE\ORACLE_HOME, 2-6
.NET Stored Procedures, 2-1 OracleClrAgent service, 8-1
.NET stored procedures, 1-2, 2-2 OracleCommand class, 4-1, 4-2, 4-4
deployment, 8-1 using stored procedure, 6-9
.NET Types, 9-13 OracleConnection class, 3-10, 9-8
New Package Window, 6-2, 6-8 GetSessionInfo() method, 9-9
New Project dialog, 3-1 Open() method, 9-8
NLS error messages setting, 9-6 OracleDataAccess.dll, 3-4
NLS number formats OracleDataReader class, 4-2, 4-6, 4-8
settings, 9-4 OracleDbType property, 4-4
NLS sort order, 9-5 OracleError class, 3-14
NLS_LANG parameter, 9-8 OracleErrorCollection class, 3-14
NLS_LANGUAGE parameter, 9-2, 9-6, 9-7 OracleException class, 3-14, 3-16
NLS_SORT parameter, 9-5 OracleGlobalization
NLS_TERRITORY parameter, 9-2, 9-4, 9-7 class, 9-9
GetClientInfo() method, 9-8
O OracleGlobalization class
GetThreadInfo() method, 9-13
ODAC (Oracle Data Access Components), 2-2
SetThreadInfo() method, 9-13
ODP.NET Types, 9-13
OracleParameter class, 4-4, 6-9
Open() method, 3-10, 9-8
OracleParameterCollection class, 4-4
opening connection, 3-10
OracleRefCursor class, 6-2
Oracle Data Access Components (ODAC), 2-2
OracleService, A-1
downloading, 2-2
Index-3
OraProvCfg, 2-8 definition, 6-2
OUI (Oracle Universal Installer), 2-2 introduction, 6-2
PL/SQL data type, 6-2
PL/SQL stored procedures, 6-2, 6-8
P
references
package bodies, 6-1 adding, 3-4
package interfaces, 6-1 result set, 6-2
PACKAGE types, 6-1 retrieving data
packages accessor type, 4-2
new, 6-2, 6-8 bind variables, 4-4
ParameterName, 4-4 from Oracle, 7-2
passwords looping, 4-6
save, 5-1 multiple columns, 4-6
PL/SQL packages multiple rows, 4-6
body, 6-1 multiple values, 4-6
definition, 6-1 simple query, 4-2
interface, 6-1 value methods, 4-2
introduction, 6-1 roles
PL/SQL stored procedures user default, 5-1
definition, 6-1 Run Function window, 8-12
in ODP.NET, 6-9 running .NET procedures in Query Window, 8-13
introduction, 6-1 running .NET procedures in SQL, 8-13
REF CURSORs, 6-2, 6-8
preview SQL, 5-5, 6-2, 6-8
primary key
S
column, 5-10 sample data, 2-1
privileges sample schemas, 2-1
granting, 2-9 Save command, 3-5
projects schema object, 1-2, 8-2
add reference, 3-4 schemas
new, 3-1 display, 5-1, 8-2
solution, 3-1 security, 7-1
type SELECT statements
Visual Basic, 3-1 bind variables, 4-4
Visual C#, 3-1 simple, 4-4
properties Server Explorer, 1-2, 6-8
Direction, 4-4 using, 5-1
Error, 3-14 service_name, A-1
OracleDBType, 4-4 Services, A-1
OracleDBType property, 4-4 session globalization setting, 9-9
ParameterName, 4-4 SetThreadInfo() method, 9-13
Size, 4-4 setup for Oracle Providers for ASP.NET, 2-8
Value, 4-4 simple query, 4-2
Properties window, 3-7 Size property, 4-4
solution, 3-1
specify copy options window, 8-7
Q
specify deployment option window, 8-7
query performance, 4-4 specify methods and security details window, 8-7
Query Window SQL preview, 5-5
running .NET procedures, 8-13 SQL query, 4-1
query work area SQL statement string, 4-1
definition, 6-2 SQL*Plus, 9-2
connecting to, 9-2
R sqlnet.ora, 2-7
start Oracle Database Instance, A-1
Rebuild Solution, 3-15 Start Without Debugging, 7-20
records, 4-12 statements
add, 5-13 case, 3-16
REF CURSORs Imports, 3-5
accessibility, 6-2 optimizing, 4-4
assigning, 6-2, 6-8
Index-4
parsing, 4-4 user_source view, 6-1
reusing, 4-4 users
using, 3-5 creating, 2-9
stop Oracle Database Instance, A-1 locale settings, 9-7
stored procedures role, 5-1, 8-2
creating Oracle Project to hold, 8-4 using statements, 3-5
definition, 6-1
run, 8-12
V
Summary
of deployment, 8-7 Value property, 4-4
SYSDBA variable declarations, 4-8
connecting as, 8-7 View menu, 3-7
System.Globalization, 9-1 views
System.Resources, 9-1 Design, 5-5
System.Threading.Thread.CurrentThread.CurrentCul table design, 5-8
ture parameter, 9-13 user_source, 6-1
Visual Basic (VB) statements
Imports, 3-5
T Visual Studio, 1-3
table design views, 5-8 versions, 2-2
table design windows, 5-5
tables
W
add data, 5-13
constraint name, 5-10 warning
constraint properties, 5-10 in error handling, 3-14
constraints, 5-10 web site
add, 5-12 connecting to database, 7-2
creating, 5-5 creating, 7-2
data, 5-13 web site authentication, 7-11
grid, 5-13 testing, 7-20
new, 5-5 web users
new relational, 5-5 creating, 7-13
query, 5-14 Windows Registry, 9-8
record, 5-13
relational, 5-5
retrieve data, 5-13
simple query, 5-14
testing
web site authentication, 7-20
Text property, 4-2
Textbox control, 3-7
thread-based globalization setting, 9-13
tnsnames.ora, A-1
configuring, 2-7
toolbox, 3-7
try code block, 4-1, 4-8
Try-Catch-Finally block, 3-15
Try-Catch-Finally error handling, 3-15
tutorial, 7-1
U
unlocking accounts, 5-1, 8-2
unlocking user account
Oracle Database interface, 8-7
updating data
bind variable, 4-4
user interfaces
designing, 3-7
user schema
ASPNET_DB_USER, 2-9
Index-5
Index-6