Logo
programming4us
programming4us
programming4us
programming4us
Home
programming4us
XP
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server
programming4us
Windows Phone
 
Windows Server

BizTalk 2010 Recipes : Adapters - Calling Stored Procedures

4/24/2011 6:13:56 PM

1. Problem

You need to create an orchestration that inserts a record into a table in your SQL database via a stored procedure. Specifically, you need to create an orchestration that inserts a new customer record based on an inbound message.

2. Solution

The solution reviewed as part of this recipe outlines how to use the SQL adapter within the context of an orchestration. The following instructions outline the tasks required to create and configure the physical SQL send port as well as the orchestration that implements the SQL adapter.

The solution has sample XML files to demonstrate how the SQL adapter inserts message content into a SQL table via a stored procedure. The solution also includes a sample SQL table structure.

3. Task 1: Create Supporting Artifacts

The steps outlined for this task create the supporting solution artifacts. You will create the table, stored procedure, and inbound message structure for the message consumed by BizTalk. Here are the steps to follow:

  1. Create a new SQL database and table for which to insert the record. Compile the table definition listed in Listing 1.

    Example 1. Example Customer Table Definition
    CREATE TABLE [dbo].[Customer] (
    [CustomerID][int] IDENTITY (1,1) NOT NULL,
    [CustomerName][nvarchar](30) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
    [Address][nvarchar](60) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
    [City][nvarchar](30) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
    [Region][nvarchar](30) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
    [PostalCode][nvarchar](10) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
    ) ON [PRIMARY]


  2. If you do not have a stored procedure to insert individual customer records, compile the stored procedure listed in Listing 2.

    Example 2. Example Insert Customer Stored Procedure
    if exists  (select * from sysobjects where name = 'BizTalkToCustomerInsert'
    and type = 'P')
    drop proc BizTalkToCustomerInsert
    go
    CREATE procedure BizTalkToCustomerInsert
    @CustomerName nvarchar(60)
    , @Address nvarchar(120)
    , @City nvarchar(60)
    , @Region nvarchar(60)
    , @PostalCode nvarchar(60)
    AS
    /*
    **
    ** Object: BizTalkToCustomerInsert
    **
    ** Description: Inserts records into the Customer table for the SQL adapter
    ** stored procedure recipe
    **
    **
    */
    BEGIN
    Declare @intReturnCode int
    select @intReturnCode = 0

    /*Insert records that will be returned to caller*/
    Insert Customer (CustomerName, Address, City, Region, PostalCode)
    Values (@CustomerName, @Address, @City, @Region, @PostalCode)

    /* Set the outbound return code */
    select @intReturnCode = @@error

    /* return the return code */
    return @intReturnCode
    END

    go
    grant execute on dbo.BizTalkToCustomerInsert to public
    go


  3. Create a new BizTalk solution that will contain the components used to insert customers into the Customer table in your SQL database. Next, create a sample message that matches the structure detailed in Listing 3. The schema for this message will be created as part of the solution as defined in the "Task 2: Create BizTalk Solution Artifacts" section of this recipe.

    Example 3. Example Customer Input Message
    <ns0:Customer_Request xmlns:ns0="http://SQLAdapterStoredProcedure">
    <ns0:BizTalkToCustomerInsert Address="1241 Little Overlook" City="Grand Jct" CustomerName="Ciro
    A" PostalCode="81502" Region="CO" />
    </ns0:Customer_Request>


4. Task 2: Create BizTalk Solution Artifacts

Next, you will be using the Add Generated Items Wizard to generate the BizTalk artifacts for this recipe. The wizard will prompt you to specify your BizTalk environment (such as specifying the BizTalk MessageBox database, setting the connection string to the database that you will be accessing, and identifying the type of SQL port you are creating such as send or receive). Follow these steps:

  1. Choose Add Generated Items from the Solution Explorer's tool menu. Verify that Add Adapter Metadata is selected.

  2. On the Add Adapter Wizard page, select the SQL adapter, and verify the settings to your BizTalk MessageBox database. Figure 1 shows the initial connection screen.

    NOTE

    You can leave the Port field empty unless you are specifying an already created SQL send or receive port. This sample will create a send port that you will specify later.

    Figure 1. Using the Add Generated Items Wizard
  3. Click Next, and set the connection string for the database to which you are connecting.

  4. Click Next, and specify the target namespace as http://SQLAdapterStoredProcedure, the port type as Send, the request document root element name as Customer_Request, and the response document root element name as Customer_Response. The wizard should look like Figure 2.

    Figure 2. Using the SQL Transport Schema Generation Wizard
  5. On the Statement Type page of the wizard, select Stored Procedure as the type of statement, and click Next.

  6. On the Statement Information page of the wizard, select the BizTalkToCustomerInsert stored procedure from the drop-down enumeration, and leave all the check boxes next to the input parameters empty.

  7. Finally, click the Generate button, because it results in a generated execute script that is listed in the Generated Script field of the wizard. The wizard should resemble Figure 3.

    Figure 3. Using the SQL Transport Generation Wizard—the Statement Information page

    NOTE

    Because the stored procedure contains input parameters, they are displayed in the datagrid of the wizard. If there are default values that should be specified, you can enter those parameters next to the name of the input parameter. If the check box is selected, a null value will be submitted as the value for the input parameter.

  8. Click Next and then Finish, completing the wizard. When you complete the wizard, notice that BizTalk creates two artifacts for you: the BizTalk orchestration and SQLService.xsd.

    NOTE

    The BizTalk orchestration allows you to perform additional processing of the inbound message, and the SQLService schema contains the physical representation of the data returned from the stored procedure.

  9. Configure the BizTalk orchestration for an inbound receive and an outbound send. The ports should be configured to receive and to send a message of type SQL_Adapter_Stored_Procedure.SQLService.Customer_Request. Your orchestration should resemble Figure 4. Make sure to set the Activate property on the Receive shape to True.

    Figure 4. Configuring the SQL stored procedure orchestration
  10. Build and deploy your BizTalk solution.

5. Task 3: Create Physical BizTalk Ports

Your next task is to create the physical BizTalk ports you will need to test the solution. Follow the process outlined in these steps:

  1. To test this solution, you will need to create a physical file receive port to consume the inbound XML file and a SQL send port to send the message to the SQL database. Open the BizTalk Administration Console.

  2. Find the appropriate BizTalk application, right-click the Send Ports folder, and select New→Static One-way Send Port to open the Send Port Properties dialog box. Name the new send port Sample SQL Stored Procedure Send Port. Within the Transport section of the General tab, select SQL from the Type drop-down list.

  3. In the SQL Transport properties, configure the connection string to the appropriate database by clicking the ellipses next to the Connection String field. Additionally, configure the document target namespace as http://SQLAdapterStoredProcedure.

  4. Set Send Pipeline to the Microsoft.BizTalk.DefaultPipelines.XMLTransmit pipeline.

  5. Bind the deployed orchestration to the newly created send and receive ports.

6. Task 4: Test the Solution

Your last task is to test your solution to be sure it works correctly. The procedure for testing is simple: place your sample customer test file in the folder being monitored by the file receive port, and verify that the record inserted successfully into the Customer table.

7. How It Works

Utilizing the SQL adapter to call stored procedures is a great way to insert data into a database or call a procedure to return data from a database. The benefits of using the SQL adapter over creating a component to make database calls include being able to use any BizTalk adapter (including guaranteed reliable message delivery, retry capabilities, and the ability to specify alternative mechanisms for message delivery). Additionally, a stored procedure is capable of taking an entire XML message or individual data elements as input parameters.

This recipe demonstrates how to use the SQL adapter and stored procedure to insert customer records in a SQL table. The stored procedure required input parameters but could have taken the entire contents of the XML message and parsed the contents of message.

Other -----------------
- Deploying a Prototype Lab for the Exchange Server 2010 Transition Process
- Understanding What’s New and What’s Different with Exchange Server 2010
- Understanding How to Transition to Exchange Server 2010
- BizTalk 2010 Recipes : Adapters - Sending Updategrams
- BizTalk 2010 Recipes : Adapters - Configuring MSMQ Receives
- BizTalk 2010 Recipes : Adapters - Configuring MSMQ Sends
- Windows Server 2008 R2 : Windows Media Services - Broadcasting a Live Event
- Windows Server 2008 R2 : Windows Media Services - Understanding Windows Media Encoder
- Windows Server 2008 R2 : Windows Media Services - Combining Multiple Files for a Combined Single Broadcast
- High-Level Guide for Transition from Exchange Server 2007 to Exchange Server 2010
 
 
Top 10 video Game
-   Renoir [PS4/XOne/PC] Kickstarter Trailer
-   Poly Bridge [PC] Early Access Trailer
-   Renoir [PS4/XOne/PC] Gameplay Explanation Trailer
-   Renoir [PS4/XOne/PC] More About Trailer
-   King's Quest: A Knight to Remember [PS3/PS4/X360/XOne/PC] Complete Collection Trailer
-   Samurai Warriors Chronicles 3 | Announcement Trailer
-   FIFA 16 | No Touch Dribbling with Lionel Messi
-   Why We're Cautiously Optimistic For The Final Fantasy VII Remake
-   Civilization: Beyond Earth – Rising Tide [PC] E3 Gameplay Walkthrough
-   Why We're Excited For the FFVII Remake
-   Mortal Kombat X | Predator Brutality
-   Mortal Kombat X | Predator Fatality
-   Poly Bridge [PC] Early Access Trailer
-   Silence: The Whispered World 2 [PS4/XOne/PC] Cinematic Trailer
-   Devilian [PC] Debut Trailer
Popular tags
Microsoft Access Microsoft Excel Microsoft OneNote Microsoft PowerPoint Microsoft Project Microsoft Visio Microsoft Word Active Directory Biztalk Exchange Server Microsoft LynC Server Microsoft Dynamic Sharepoint Sql Server Windows Server 2008 Windows Server 2012 Windows 7 Windows 8 windows Phone 7 windows Phone 8
programming4us programming4us
 
Popular keywords
HOW TO Swimlane in Visio Visio sort key Pen and Touch Creating groups in Windows Server Raid in Windows Server Exchange 2010 maintenance Exchange server mail enabled groups Debugging Tools Collaborating
programming4us programming4us
PS4 game trailer XBox One game trailer
WiiU game trailer 3ds game trailer
Trailer game
 
programming4us
Heroes Charge
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server
programming4us
Game Trailer