4 Development and Deployment of a .NET Stored Function Demo
These topics demonstrate how to develop and deploy a .NET stored function.
See Also:
Oracle Developer Tools for Visual Studio Help for further information for further information about these components
Overview of .NET Stored Function Demonstration
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.
Step 1: Create the GetDeptNo Function and Build it into an Assembly
This demonstration begins by opening Visual Studio, creating a function, and building it into an assembly.
Step 2: Start the Oracle Deployment Wizard for .NET
Oracle Deployment Wizard for .NET can be started from the build menu.
Step 3: Choose the Function to Deploy
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:
Step 4: Determine the Appropriate Parameter 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.
See Also:
"Data Type Conversion" for data type mapping tables
Step 5: Deploy the Function to an Oracle Database
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:
Step 6: Test the 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:
Invoking from Oracle Developer Tools for Visual Studio
To locate and call the function from Oracle Developer Tools for Visual Studio:
Invoking from ODP.NET client
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