PK
(–Aoa«, mimetypeapplication/epub+zipPK (–A iTunesMetadata.plistuŠû
This section describes new features in Oracle Database Extensions for .NET and provides references to additional information.
The following section describes the new features in Oracle Database Extensions for .NET.
New Features in Oracle Database Extensions for .NET Release 11.2.0.1.2
New Features in Oracle Database Extensions for .NET Release 11.1.0.6.20
Oracle Database Extensions for .NET release 11.2.0.1.2 includes the following:
.NET Framework 4 support
Oracle Database Extensions for .NET Framework 4 supports .NET Framework 4.
Oracle Database Extensions for .NET release 11.1.0.6.20 includes the following:
Support for Unloading .NET Assemblies
You may unload .NET assemblies after .NET stored procedure execution is complete. This feature enables you to redeploy and to test code without having to restart extproc
.
Support for Nullable Types
Oracle Database Extensions for .NET now supports nullable types as procedure or function parameters.
Extensions for .NET Developer's Guide
11g Release 2 (11.2) for Microsoft Windows
E17724-01
October 2010
Oracle Database Extensions for .NET Developer's Guide, 11g Release 2 (11.2) for Microsoft Windows
E17724-01
Copyright © 2004, 2010, Oracle and/or its affiliates. All rights reserved.
Primary Author: Janis Greenberg
Contributors: Kiminari Akiyama, Neeraj Gupta, Shailendra Jain, Chithra Ramamurthy, Gnanaprakash Rathinam, Christian Shay, Subramanian Venkatraman
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.
This chapter demonstrates how to develop and deploy a .NET stored function.
This chapter contains these topics:
See Also: Oracle Developer Tools for Visual Studio Help for further information for further information about these components |
This demonstration uses Oracle Developer Tools for Visual Studio extensively although some processes can be performed with other Oracle tools. Also, the demonstration refers to the following components of Oracle Developer Tools for Visual Studio:
Oracle Explorer
Oracle Project
Oracle Deployment Wizard for .NET
In this demonstration, you will develop and deploy a .NET stored function named GetDeptNo
, with a PL/SQL wrapper, GETDEPTNO
. The GetDeptNo
function accepts an employee number (EMPNO
), performs a query, and returns the department number (DEPTNO)
of the employee.
This demonstration begins by opening Visual Studio, creating a function, and building it into an assembly.
Open Visual Studio and connect as scott/
password
. See Oracle Developer Tools for Visual Studio Help for information about connecting.
From the Visual Studio menu, select File, then New Project.
To create an Oracle Project template, select the project type Visual C# Projects, and select Oracle Project.
Name the project CLRLibrary1
and provide a location for it.
A class named CLRLibrary1.Class1
appears. It contains a template for a stored procedure.
Copy the following code over the base class and save.
using System; // use the ODP.NET provider using Oracle.DataAccess.Client; using Oracle.DataAccess.Types; namespace CLRLibrary1 { // Sample .NET stored function returning department number for // a given employee number public class Class1 { public static int GetDeptNo(int empno) { int deptno = 0; // Check for context connection OracleConnection conn = new OracleConnection(); if( OracleConnection.IsAvailable == true ) { conn.ConnectionString = "context connection=true"; } else { throw new InvalidOperationException("context connection" + "not available"); } conn.Open(); // Create and execute a command OracleCommand cmd = conn.CreateCommand(); cmd.CommandText = "SELECT DEPTNO FROM EMP WHERE EMPNO = :1"; cmd.Parameters.Add(":1",OracleDbType.Int32,empno, System.Data.ParameterDirection.Input); OracleDataReader rdr = cmd.ExecuteReader(); if (rdr.Read()) deptno = rdr.GetInt32(0); rdr.Close(); cmd.Dispose(); conn.Close(); return deptno; } // GetDeptNo } // Class1 } // CLRLibrary1
From the Build menu, select Build Solution or Build CLRLibrary1.
This builds the code into an assembly.
Save.
Oracle Deployment Wizard for .NET can be started from the build menu.
From the Build menu, select Deploy CLRLibrary1.
When the Welcome window appears, select Do not show this page again, if you want.
Then, click Next.
The Configure your OracleConnection window appears.
Choose your connection from the drop-down list, and click Next or click New Connection, if you are not connected.
You must choose or add a SYSBA
connection.
If you have selected New Connection, the Add Connection window appears.
In the Connection Details tab, select the Data source name from the drop-down list.You can select an option to Use Windows integrated authentication or an option Use a specific user name and password, and enter that information.If you want, select Save password.The option for Role shows SYSDBA
, which is the only available option.If you want to test the connection, click Test connection.Click OK,
The Specify your deployment option window appears.
The first time you run the deployment wizard, select Copy assembly and generate stored procedures. If you later modify your function or stored procedure, you can run the deployment wizard again, and choose to perform just one of these operations.Click Next.
The Specify an assembly and library name window appears.
To specify the assembly, select the project from the drop-down list, or select File, and click Browse to navigate to the one you want.
To specify the name of the library database object to be used for the selected assembly, accept the default, select the name from the drop-down list, or enter a new name.
For this demonstration, accept the default project and library name and click Next.
The Specify Copy Options window appears.
To specify the dependent assemblies to copy to the database, select them from the list. The list displays all possible dependent assemblies. In this case, the assemblies displayed have already been copied to the database and, therefore, there is no need to copy them. To deploy the assembly to a directory other than the default bin\clr
directory, modify the destination path. The destination must be a bin\clr
directory or one of its existing subdirectories.
For this demonstration, do not select any dependent assemblies, and do not modify the destination path.
If you want to, select Overwrite the file if it already exists in the database.
Then, click Next.
The Specify methods and security details window appears.
You can select the entire project to deploy, or expand it to deploy specific functions. Because there is only one function in this project, selecting any one item, checks the entire project. If there were more functions or procedures, you could select individual items to deploy.
If you want to select a different schema to deploy, you can do so here. If the schema you want is not listed, you need to apply different filters. For information on this process, see Oracle Developer Tools for Visual Studio Help.
You can set the security level using the drop-down list. The possible levels are:
Safe - (Default)
External
Unsafe
For this demonstration, do the following:
Choose GetDeptNo()
from the list of procedures and functions contained within that assembly.
The schema initially says SYS
. Change it to Scott
, so that you can deploy it in the scott
schema.
Accept the default security level. You can either click Next to continue, or you can click Parameter Type Mapping... to view the type mappings.
If you have selected Parameter Type Mapping..., the Parameter Type Mapping window appears, which allows you to change the data type, using the drop-down list.
For this demonstration, accept the default mappings of the .NET data type System.Int32
to the Oracle type BINARY_INTEGER
.
Click OK to return to the Specify methods and security details window.
The Summary window of the Oracle Deployment Wizard for .NET appears, showing all the indicated specifications. This window permits you to modify any values by selecting Back.
To complete the demonstration, do the following:
Review the summary.
To verify SQL commands, select Show Script.
When the Show Sql window appears, review the code for the PL/SQL wrapper and click OK to return to the Summary window.
Click Finish to deploy the GetDeptNo()
function.
At this point, GetDeptNo()
function has been deployed to the Oracle Database and you are ready to test it by invoking the PL/SQL wrapper function.
You must be connected as the default user, scott
, in this demonstration, to call the function.
Test the function by invoking it from the following tools:
To locate and call the function from Oracle Developer Tools for Visual Studio:
From the View menu, select Oracle Explorer.
Expand the Functions node.
Locate GETDEPTNO.
Right-click GETDEPTNO and from the menu, select Run.
When the Run Function dialog box appears, enter employee number 7934 as the input value.
Click OK.
The output value 10 appears in the Document Window, indicating that employee number 7934 belongs to department 10.
The following code sample demonstrates how to invoke the PL/SQL wrapper for .NET function.
using System; using System.Data; using Oracle.DataAccess.Client; namespace ODPNETClientApp { public class Class1 { public static void Main() { int empno = 7934; int deptno = 0; try { // Open a connection to the database OracleConnection con = new OracleConnection( "User Id=scott; Password=tiger; Data Source=inst1"); con.Open(); // Create and execute the command OracleCommand cmd = con.CreateCommand(); cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "GETDEPTNO"; // Set parameters OracleParameter retParam = cmd.Parameters.Add(":DEPTNO", OracleDbType.Int32, System.Data.ParameterDirection.ReturnValue); cmd.Parameters.Add(":EMPNO", OracleDbType.Int32, empno, System.Data.ParameterDirection.Input); cmd.ExecuteNonQuery(); deptno = (int)retParam.Value; Console.WriteLine("\nEmployee# {0} working in department# {1}\n", empno, deptno); cmd.Dispose(); con.Close(); } catch (Exception e) { Console.WriteLine(e.Message); } } } // Class1 } // ODPNETClientApp namespace
To invoke the GetDeptNo()
function .NET function from SQL* Plus:
Start SQL*Plus and log in as user scott
with the password tiger
.
Enter the following commands:
SET SERVEROUTPUT ON; DECLARE deptno BINARY_INTEGER; BEGIN deptno := GetDeptNo(7934); DBMS_OUTPUT.PUT_LINE(deptno); END;
Alternatively, you can execute following statement:
SELECT GetDeptNo(7934) FROM DUAL;
See Also:
|
This chapter introduces Oracle Database Extensions for .NET, which makes it possible to build and run .NET stored procedures or functions with Oracle Database for Microsoft Windows.
This chapter contains these topics:
Oracle Database Extensions for .NET provides the following:
A Common Language Runtime (CLR) host for Oracle Database
Data access through Oracle Data Provider for .NET classes
Oracle Deployment Wizard for Visual Studio
The Oracle Database hosts the Microsoft Common Language Runtime (CLR) in an external process, outside of the Oracle database process. The integration of Oracle Database with the Microsoft Common Language Runtime (CLR) enables applications to run .NET stored procedures or functions on Oracle Database, on Microsoft Windows Vista, Windows 2003, Windows 2000, and Windows XP.
Application developers can write stored procedures and functions using any .NET compliant language, such as C# and VB.NET, and use these .NET stored procedures in the database, in the same manner as other PL/SQL or Java stored procedures. .NET stored procedures can be called from PL/SQL packages, procedures, functions, and triggers; from SQL statements, or from anywhere a PL/SQL procedure or function can be called.
Application developers build .NET procedures or functions into a .NET assembly, typically using Microsoft Visual Studio. Oracle Data Provider for .NET is used in .NET stored procedures and functions for data access. After building .NET procedures and functions into a .NET assembly, developers deploy them in Oracle Database, using the Oracle Deployment Wizard for .NET, a component of the Oracle Developer Tools for Visual Studio.
The .NET stored procedure or function appears to the caller as a PL/SQL stored procedure or function because a PL/SQL wrapper has been generated for it. The user invokes a .NET stored procedure or function through this PL/SQL wrapper. Oracle Deployment Wizard for .NET determines the probable mappings between Oracle data types and .NET data types, which the user can override. The mappings are handled seamlessly by the PL/SQL wrapper.
This architecture diagram shows the client application and then two process spaces, the Oracle process space and the external process space.
The Oracle process space includes the Oracle database instance and hosts the PL/SQL wrapper.
The external process space includes the Oracle CLR host, in which .NET stored procedures or functions are executed.
The Oracle CLR host is installed as part of Oracle Database Extensions for .NET installation and runs in the extproc
process. The extproc
process loads the Oracle CLR host which in turn loads an instance of the Microsoft Common Language Runtime (CLR), thus providing an interface for the wrapped PL/SQL procedure. These mechanics are not visible to the users. From a user's point of view, the application is invoking just another PL/SQL stored procedure or function.
Note: The Microsoft .NET Framework must be installed on the same computer as the database. |
.NET stored procedures or functions are hosted in a process external to the Oracle Database. This external process is a heterogeneous service agent called extproc
, external procedure agent, or external process. This guide uses the terms extproc
process or extproc
agent.
See Also: Oracle Database Heterogeneous Connectivity Administrator's Guide |
The extproc
process supports the following architectures:
In dedicated (that is, single-threaded) agent architecture, an extproc
process is started for each user session. The process terminates when the user session ends. This architecture can consume an unnecessarily large amount of system resources since, with every user session, a new extproc
process must be started and shut down. Therefore dedicated agent architecture does not perform well in terms of system resources and runtime efficiency.
A multithreaded extproc
process uses a pool of shared threads. The tasks requested by the user sessions are put on a queue and are picked up by the first available thread.
Multithreaded agent architecture allows more efficient use of system resources than dedicated architecture.
A separate multithreaded extproc
process must be started for each system identifier (SID). Each TNS listener that is running on a system listens for incoming connection requests for a set of SIDs. If the SID in an incoming Oracle Net connect string is one that the listener is listening for, then that listener processes the connection. If a multithreaded process has been started for the SID, then the listener passes the request to that process.
See Also:
|
The Oracle multithreaded extproc
process is tightly coupled with the Oracle listener. Therefore, each node in a Real Application Clusters (RAC) environment has an Oracle multithreaded extproc
process associated with the listener on that node.
The following are typical examples of the listener.ora
and tnsnames.ora
files configured for Oracle Database Extensions for .NET. By default, Oracle Database Extensions for .NET uses CLRExtProc
as the SID, but this can be changed using the Database Configuration Assistant (DBCA).
Listener.ora file
SID_LIST_LISTENER = (SID_LIST = (SID_DESC = (SID_NAME = PLSExtProc) (ORACLE_HOME = C:\oracle\database_1) (PROGRAM = extproc) ) (SID_DESC = (SID_NAME = CLRExtProc) (ORACLE_HOME = C:\oracle\database_1) (PROGRAM = extproc) (ENVS="EXTPROC_DLLS=ONLY:C:\oracle\database_1\bin\oraclr11.dll") ) ) LISTENER = (DESCRIPTION_LIST = (DESCRIPTION = (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1)) ) )
Tnsnames.ora File
ORACLE = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = user.us.oracle.com)(PORT = 1521)) ) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = oracle.us.oracle.com) ) ) ORACLR_CONNECTION_DATA = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1)) ) (CONNECT_DATA = (SID = CLRExtProc) (PRESENTATION = RO) ) ) MSOLNIT-PC = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = msolnit-pc)(PORT = 1521)) ) (CONNECT_DATA = (SERVICE_NAME = orcl) ) ) EXTPROC_CONNECTION_DATA = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1)) ) (CONNECT_DATA = (SID = PLSExtProc) (PRESENTATION = RO) ) )
Oracle Data Provider for .NET provides data access to the Oracle Database from any client application. Oracle Data Provider for .NET is available for free download on Oracle Technology Network (OTN).
See Also: Oracle Data Provider for .NET Developer's Guide for detailed descriptions of ODP.NET classes |
Oracle Developer Tools for Visual Studio is a set of application tools tightly integrated with the Visual Studio development environment. Oracle Developer Tools enables developers to execute a wide range of application development tasks, such as creating tables, editing stored procedures, and viewing data in the Oracle Database. Oracle Developer Tools for Visual Studio is available for free download on Oracle Technology Network (OTN).
See Also: Oracle Developer Tools for Visual Studio Help |
The Oracle Deployment Wizard for .NET is a graphical tool integrated with Microsoft Visual Studio which makes it easy to deploy any .NET procedure or function into an Oracle Database. It is installed as part of Oracle Developer Tools for Visual Studio.
See Also: Oracle Developer Tools for Visual Studio Dynamic Help, available by installing Oracle Developer Tools for Visual Studio, for more information |
This appendix discusses common errors.
Users may encounter various errors while running the PL/SQL wrapper. Causes and recommended actions for such errors are listed below.
extproc
crashes for some reason.alert.log
file for any errors. Finally, test to see whether the server process is dead and whether a trace file was generated at failure time. There may be some system calls in the .NET function which might terminate the process. Remove such calls.extproc
crashes for some reason.alert.log
file for any errors. Finally, test to see whether the server process is dead and whether a trace file was generated at failure time. There may be some system calls in the .NET function which might terminate the process. Remove such calls.ORACLE_BASE\\ORACLE_HOME
\bin\clr
or in one of the subdirectories as specified during the creation of the library object by the wizard.ORACLE_BASE\\ORACLE_HOME
\bin\clr
or to one of its subdirectories as appropriate.MissingMethodException
is thrown for many possible reasons including:
The stored procedure or function name does not match the actual stored procedure or function name defined in the .NET assembly.
The number, sequence, and type of parameters passed do not match the actual parameters in the .NET stored procedure.
extproc
agent did not succeed. This problem can be caused by network problems, incorrect listener configuration, or incorrect transfer code.LISTENER.ORA
and TNSNAMES.ORA
, or check Oracle Names Server. Verify that the multithreaded extproc
configuration entries are correct.assembly
Assembly is the Microsoft term for the module that is created when a DLL or .EXE is complied by a .NET compiler.
Common Language Runtime
Microsoft Common Language Runtime (CLR) is the component of the .NET framework that allows many languages to create and develop applications using the same library.
external procedure
A function written in a third-generation language (3GL), such as C, and callable from within PL/SQL or SQL as if it were a PL/SQL function or procedure.
Microsoft .NET Framework Class Library
The Microsoft .NET Framework Class Library provides the classes for the .NET framework model.
namespace
.NET:
A namespace is naming device for grouping related types. More than one namespace can be contained in an assembly.
XML Documents:
A namespace describes a set of related element names or attributes within an XML document.
Oracle Net Services
The Oracle client/server communication software that offers transparent operation to Oracle tools or databases over any type of network protocol and operating system.
stored function
A stored function is a PL/SQL block that Oracle stores in the database and can be executed from an application.
This document describes the features of Oracle Database for Windows software installed on Windows 2003, Windows 2000, and Windows XP Professional operating systems.
This guide describes Oracle Database Extensions for .NET, which provides a Common Language Runtime (CLR) host for Oracle Database and data access through Oracle Data Provider for .NET (ODP.NET) classes.
This preface contains these topics:
Oracle Database Extensions for .NET Developer's Guide is intended for programmers who are developing applications to access an Oracle Database using Oracle Database Extensions for .NET. This documentation is also valuable to systems analysts, project managers, and others interested in the development of database applications.
To use this document, you must be familiar with Microsoft .NET Framework classes and ADO.NET and have a working knowledge of application programming using Microsoft C#, Visual Basic, or another .NET language.
Users should also be familiar with the use of Structured Query Language (SQL) to access information in relational database systems.
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/
.
Accessibility of Code Examples in Documentation
Screen readers may not always correctly read the code examples in this document. The conventions for writing code require that closing braces should appear on an otherwise empty line; however, some screen readers may not always read a line of text that consists solely of a bracket or brace.
Accessibility of Links to External Web Sites in Documentation
This documentation may contain links to Web sites of other companies or organizations that Oracle does not own or control. Oracle neither evaluates nor makes any representations regarding the accessibility of these Web sites.
Access to Oracle Support
Oracle customers have access to electronic support through My Oracle Support. For information, visit http://www.oracle.com/support/contact.html
or visit http://www.oracle.com/accessibility/support.html
if you are hearing impaired.
For more information, see these Oracle resources:
Oracle Developer Tools for Visual Studio Help
Oracle Data Provider for .NET Developer's Guide
Oracle Database PL/SQL Packages and Types Reference
Oracle Database SQL Reference
Oracle Database Installation Guide for Windows
Oracle Database Release Notes for Windows
Oracle Database Platform Guide for Windows
Oracle Database New Features
Oracle Net Services Reference Guide
Many of the examples in this book use the sample schemas, which are installed by default when you select the Basic Installation option with an Oracle Database installation. Refer to Oracle Database Sample Schemas for information on how these schemas were created and how you can use them yourself.
To download free release notes, installation documentation, white papers, or other collateral, please visit the Oracle Technology Network (OTN). You must register online before using OTN; registration is free and can be done at
http://www.oracle.com/technology/membership/
If you already have a username and password for OTN, then you can go directly to the documentation section of the OTN Web site at
http://www.oracle.com/technology/documentation/
For simplicity in demonstrating this product, code examples do not perform the password management techniques that a deployed system normally uses. In a production environment, follow the Oracle Database password management guidelines, and disable any sample accounts. See Oracle Database Security Guide for password management guidelines and other security recommendations.
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. |