Run SQLEXECUTE operation in Oracle Database using BizTalk Server
The Oracle Database adapter enables clients to run parameterized SQL statement on an Oracle database. To support such operations, the Oracle Database adapter surfaces a SQLEXECUTE operation. SQLEXECUTE operation supports an input parameter block comprised of parameter sets that enable you to execute the same SQL statement once for each set. The SQLEXECUTE operation returns the results of the SQL statement in a generic record set. For more information about the operation, see SQLEXECUTE Operation in Oracle Database. For information about the structure of the SOAP message for SQLEXECUTE operation, see Message Schemas for the SQLEXECUTE Operation.
How to Perform a SQLEXECUTE operation on an Oracle Database?
Performing an operation on an Oracle database using Oracle Database adapter with BizTalk Server involves procedural tasks described in Building blocks to develop BizTalk Applications with Oracle Database. To perform a SQLEXECUTE operation, these tasks are:
Create a BizTalk project and generate schema for the SQLEXECUTE operation. The SQLEXECUTE operation is surfaced under the root node (/) in the Select a category pane in the Consume Adapter Service BizTalk Project Add-in.
Create messages in the BizTalk project for sending and receiving messages from the Oracle database.
Create an orchestration to invoke the operation on the Oracle database table or view.
Build and deploy the BizTalk project.
Configure the BizTalk application by creating physical send and receive ports.
Start the BizTalk application.
This topic provides instructions to perform these tasks.
Sample Based On This Topic
A sample, SqlExec, based on this topic is also provided with the BizTalk Adapter Pack. For more information, see Adapter Samples.
Generating Schema
In this topic, to demonstrate how to run a parameterized SQL query, we will generate schema for SQLEXECUTE operation available at the root node (/) in the Select a category pane in the Consume Adapter Service Add-in. See Retrieve metadata for Oracle Database operations in Visual Studio for more information about how to generate schema.
Defining Messages and Message Types
The schema that you generated earlier describes the "types" required for the messages in the orchestration. A message is typically a variable, the type for which is defined by the corresponding schema. You must link the schema you generated in the first step to the messages from the Orchestration View window of the BizTalk project.
For this topic, you must create two messages—one to send a request to the Oracle database and the other to receive a response.
Perform the following steps to create messages and link them to the schema.
To create messages and link to schema
Open the Orchestration View window of the BizTalk project, if it is not already open. To do so, click View, point to Other Windows, and then click Orchestration View.
In Orchestration View, right-click Messages, and then click New Message.
Right-click the newly created message and then select Properties Window.
In the Properties pane for Message_1, do the following:
Use this To do this Identifier Type Request. Message Type From the drop-down list, expand Schemas, and then select SqlExec.OracleDBBindingSchema.SQLEXECUTE, where SqlExec is the name of your BizTalk project. OracleDBBindingSchema is the schema generated for the SQLEXECUTE operation. Repeat step 2 to create a new message. In the Properties pane for the new message, do the following:
Use this To do this Identifier Type Response. Message Type From the drop-down list, expand Schemas, and then select SqlExec.OracleDBBindingSchema.SQLEXECUTEResponse.
Setting up the Orchestration
You must create a BizTalk orchestration to use BizTalk Server for running a parameterized SQL query using the SQLEXECUTE operation. In this orchestration, you drop a request message at a defined receive location. The Oracle Database adapter consumes this message and passes it on to the Oracle database via ODP. The response from the Oracle database is saved to another location. A typical orchestration for performing SQLEXECUTE operation on Oracle database would contain:
Send and Receive shapes to send messages to Oracle database and receive responses.
A one-way receive port to receive request messages to send to the Oracle database.
A two-way send port to send request messages to Oracle database and receive responses.
A one-way send port to send the responses from Oracle database to a folder.
A sample orchestration for the SQLEXECUTE operation resembles the following:
Adding Message Shapes
Make sure you specify the following properties for each of the message shapes. The names listed in the Shape column are the names of the message shapes as displayed in the just-mentioned orchestration.
Shape | Shape Type | Properties |
---|---|---|
ReceiveMessage | Receive | - Set Name to ReceiveMessage - Set Activate to True |
SendMessage | Send | - Set Name to SendMessage |
ReceiveResponse | Receive | - Set Name to ReceiveResponse - Set Activate to False |
SendResponse | Send | - Set Name to SendResponse |
Adding Ports
Make sure you specify the following properties for each of the logical ports. The names listed in the Port column are the names of the ports as displayed in the orchestration.
Port | Properties |
---|---|
FileIn | - Set Identifier to FileIn - Set Type to FileInType - Set Communication Pattern to One-Way - Set Communication Direction to Receive |
LOBPort | - Set Identifier to LOBPort - Set Type to LOBPortType - Set Communication Pattern to Request-Response - Set Communication Direction to Send-Receive |
SaveResponse | - Set Identifier to SaveResponse - Set Type to SaveResponseType - Set Communication Pattern to One-Way - Set Communication Direction to Send |
Specify Messages for Action Shapes, and Connect Them to Ports
The following table specifies the properties and their values that you should set to specify messages for action shapes and to link the messages to the ports. The names listed in the Shape column are the names of the message shapes as displayed in the orchestration mentioned earlier.
Shape | Properties |
---|---|
ReceiveMessage | - Set Message to Request - Set Operation to FileIn.SQLEXECUTE.Request |
SendMessage | - Set Message to Request - Set Operation to LOBPort.SQLEXECUTE.Request |
ReceiveResponse | - Set Message to Response - Set Operation to LOBPort.SQLEXECUTE.Response |
SendResponse | - Set Message to Response - Set Operation to SaveResponse.SQLEXECUTE.Request |
After you have specified these properties, the message shapes and ports are connected and your orchestration is complete.
You must now build the BizTalk solution and deploy it to a BizTalk Server. For more information, see Building and Running Orchestrations.
Configuring the BizTalk Application
After you have deployed the BizTalk project, the orchestration you created earlier is listed under the Orchestrations pane in the BizTalk Server Administration console. You must use the BizTalk Server Administration console to configure the application. For a walkthrough, see Walkthrough: Deploying a Basic BizTalk Application.
Configuring an application involves:
Selecting a host for the application.
Mapping the ports that you created in your orchestration to physical ports in the BizTalk Server Administration console. For this orchestration you must:
Define a location on the hard disk and a corresponding file port where you will drop a request message. The BizTalk orchestration will consume the request message and send it to the Oracle database.
Define a location on the hard disk and a corresponding file port where the BizTalk orchestration will drop the response message containing the response from the Oracle database.
Define a physical WCF-Custom or WCF-OracleDB send port to send messages to the Oracle database. You must also specify the action in the send port. For information about how to create WCF-Custom or WCF-OracleDB ports, see Manually configure a physical port binding to Oracle Database Adapter.
Note
Generating the schema using the Consume Adapter Service BizTalk Project Add-in also creates a binding file that contains information about the ports and the actions to be set for those ports. You can import this binding file from the BizTalk Server Administration console to create send ports (for outbound calls) or receive ports (for inbound calls). For more information, see Configure a physical port binding using a port binding file to Oracle Database.
Starting the Application
You must start the BizTalk application for performing the SQLEXECUTE operation. For instructions on starting a BizTalk application, see How to Start an Orchestration.
At this stage, make sure:
The FILE receive port to receive request messages for the orchestration is running.
The FILE send port to receive the response messages from the orchestration is running.
The WCF-Custom or WCF-OracleDB send port to send messages to the Oracle database is running.
The BizTalk orchestration for the operation is running.
Executing the Operation
After you run the application, you must drop a request message to the FILE receive location. The schema for the request message must conform to the schema for the SQLEXECUTE operation you generated earlier. The orchestration consumes the message and sends it to the Oracle database. The response from the Oracle database is saved at the other FILE location defined as part of the orchestration. See Message Schemas for the SQLEXECUTE Operation for more information about the request message schema for invoking a SQLEXECUTE operation.
Because the SQLEXECUTE operation is not surfaced under any Oracle database artifact, you can use the same schema to perform a parameterized SQL query on a view or execute a procedure that operates on some other table.
For example, the following request message performs a parameterized SELECT statement on the ACCOUNT table using the SQLEXECUTE operation. The ACCOUNT table is created under the SCOTT schema by running the SQL scripts provided with the samples. To know more about the samples, see Schema Samples.
<SQLEXECUTE xmlns="http://Microsoft.LobServices.OracleDB/2007/03/SQLEXECUTE">
<SQLSTATEMENT>select * from ACCOUNT where ACCTID=:num</SQLSTATEMENT>
<PARAMETERSCHEMA>num number</PARAMETERSCHEMA>
<PARAMETERSET>
<PARAMETERDATA xmlns="http://Microsoft.LobServices.OracleDB/2007/03">
<PARAMETER>
<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/Arrays">100000</string>
</PARAMETER>
</PARAMETERDATA>
</PARAMETERSET>
</SQLEXECUTE>
The response from Oracle database for the above request message is:
<?xml version="1.0" encoding="utf-8" ?>
<SQLEXECUTEResponse xmlns="http://Microsoft.LobServices.OracleDB/2007/03/SQLEXECUTE">
<SQLEXECUTEResult>
<GenRecordRow xmlns="http://Microsoft.LobServices.OracleDB/2007/03">
<GenRecordColumn>
<GenRecordColumn>
<ColumnName>ACCTID</ColumnName>
<ColumnValue>100000</ColumnValue>
<ColumnType>System.Decimal</ColumnType>
</GenRecordColumn>
<GenRecordColumn>
<ColumnName>NAME</ColumnName>
<ColumnValue>Kim Ralls</ColumnValue>
<ColumnType>System.String</ColumnType>
</GenRecordColumn>
<GenRecordColumn>
<ColumnName>BALANCE</ColumnName>
<ColumnValue>10000</ColumnValue>
<ColumnType>System.Decimal</ColumnType>
</GenRecordColumn>
</GenRecordColumn>
</GenRecordRow>
</SQLEXECUTEResult>
</SQLEXECUTEResponse>
Possible Exceptions
For information about the exceptions you might encounter while performing a DML operation using BizTalk Server, see Exceptions and error handling.
Best Practices
After you have deployed and configured the BizTalk project, you can export configuration settings to an XML file called the bindings file. Once you generate a bindings file, you can import the configuration settings from the file so that you do not need to create the send ports, receive ports, etc. for the same orchestration. For more information about binding files, see Reuse Oracle Database adapter bindings.
See Also
Building Blocks to Develop BizTalk Applications with Oracle Database