Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

How To Create a BizTalk Application Integration Component to Parse XML Data into SQL Server 2000


View products that this article applies to.

This article was previously published under Q299464

↑ Back to the top


Summary

This article details the steps that are required to create a BizTalk Server Application Integration Component (AIC) to parse XML data into a Microsoft SQL Server 2000 table.

↑ Back to the top


More information

NOTE: Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact a Microsoft Certified Partner or the Microsoft fee-based consulting line at (800) 936-5200. For more information about Microsoft Certified Partners, please visit the following Microsoft Web site: For more information about the support options that are available and about how to contact Microsoft, visit the following Microsoft Web site:

Steps to Create an AIC in Microsoft Visual Basic to Parse an XML Document into SQL Server 2000

  1. Create a new empty database in SQL Server 2000, start the SQL Server Query Analyzer, switch context to your newly created database, and then run the following SQL Server commands on your SQL Server 2000 computer to create the necessary tables and stored procedures: (Note that you do not need to run the first three lines if this is the first time you are running it.)
    drop procedure ReloadNews
    drop table news
    go
    
    CREATE TABLE [News] (
    	[sCat] [char] (8) NOT NULL ,
    	[sCatName] [char](64) NOT NULL ,
    	[sHeadline] [char] (128)  NOT NULL ,
    	[sURL] [varchar] (256) NOT NULL
    )
    GO
    create clustered index NewsCat on News(sCat)
    go
    
    create procedure ReloadNews
    @doc text
    as
    	begin transaction
    
    	declare @iDoc int
    	exec sp_xml_preparedocument @idoc OUTPUT, @doc
    
    	delete from news
    	
    	insert into News (sCat, sCatName, sHeadline, sURL)
    	SELECT   *
    	FROM    OPENXML (@idoc, '/list/headline',0) WITH 
    		(
    		groupid 	varchar(8),
    		groupname	varchar(64),
    		title	  	varchar(128),
    		url		varchar(256)
    		)
    	exec sp_xml_removedocument @iDoc
    
    	if (select count(*) from news) > 0 
    		commit transaction
    	else
    		rollback transaction
    
    GO
    
    grant select on News to public
    grant execute on ReloadNews to public
    
    go
    						
  2. Start Visual Basic 6.0, and then create a new ActiveX DLL project.
  3. Add the following references to the project:

    • Microsoft BizTalk Server Application Interface Components 1.0 Type Library (Btscomplib.tlb)
    • Microsoft ActiveX Data Objects 2.5 Library (Msado15.dll)
    • Microsoft XML, v3.0 (Msxml3.dll)
  4. Paste the following code into the Code window for the class:
    Implements IBTSAppIntegration
    Public Function IBTSAppIntegration_ProcessMessage(ByVal bstrDocument As String) As String
    LoadtoSQL bstrDocument
    IBTSAppIntegration_ProcessMessage = True
    End Function
    
    Function LoadtoSQL(loadtotable)
    Dim cn
    Dim cmd
    Dim xmlDOM
    
    Const adCmdStoredProc = 4
    Const adChar = 129
    Const adParamInput = 1
    
        Set xmlDOM = CreateObject("MSXML2.DOMDocument")
        xmlDOM.async = False
        xmlDOM.LoadXML loadtotable
        
        Set cn = CreateObject("adodb.connection")
        cn.Open "Provider=sqloledb; Data Source=(local);Initial Catalog=master;", "sa", ""
        
        Set cmd = CreateObject("adodb.command")
        cmd.ActiveConnection = cn
        cmd.CommandType = adCmdStoredProc
        cmd.CommandText = "ReloadNews"
        cmd.Parameters.Append cmd.CreateParameter("@doc", adChar, adParamInput, Len(xmlDOM.xml), xmlDOM.xml)
        cmd.Execute
    If Err.Number <> 0 Then
    loadtotable = "error"
    Else
    loadtotable = Err.Number
    End If
        Set cmd = Nothing
        Set cn = Nothing
        Set xmlDOM = Nothing
    End Function
    						
    NOTE: You must change the following line of code to match the data source and name of the table that you created in step two (Initial Catalog= ) and provide the appropriate values for the user name and password:
    cn.Open "Provider=sqloledb; Data Source=(local);Initial Catalog=master;", "sa", "password"
    					
  5. Rename the class to loadtotable, save the project as Loadtotable.vbp, and then compile and make Loadtotable.dll.
  6. Register the DLL on the BizTalk Server computer. (Type regsvr32 loadtotable.dll from a command prompt.)
  7. Start the Component Services Microsoft Management Console (MMC) interface. To do this, click Start, point to Programs, point to Administrative Tools, and then click Component Services.
  8. Click to expand the Component Services MMC snap-in, and continue expanding until you reach COM+ Applications.
  9. Right-click COM+ Applications, click New, click Application, and then click Next.
  10. Click Create an empty application.
  11. Enter a name for the application, and then click Next.
  12. Click the This user: radio button and type in the username and password for the account that you want this application to run under.
  13. Click Finish.
  14. Navigate through the list of COM+ applications and expand your newly created application.
  15. Right-click the Components folder for this application, click New, click Component, and then click Next.
  16. Click Install new component(s), browse to the DLL that you created in step 5, select the DLL, click Open, click Next, and then click Finish.
You now have a BizTalk Application Integration component to parse an XML stream into a SQL Server table. If you expand the Components folder, you can see the interfaces for your component, including the IBTSAppIntegration interface that BizTalk Server needs to call the component.

To test this Application Integration Component, create a file receive function to grab the News.xml file that is extracted from the News.exe download, and then hand it off to a channel that is matched to a port that has a primary transport of Application Integration Component. Because the component exposes the IBTSAppIntegration interface, you can browse to the component when you choose the component name for a transport type of Application Integration Component when you configure the destination port in the Messaging Manager.

The following file is available for download from the Microsoft Download Center:
The News.exe file contains the following files:

Collapse this tableExpand this table
File NameSize
News.xml46.8 KB (47,938 bytes)


For additional information about how to download Microsoft Support files, click the following article number to view the article in the Microsoft Knowledge Base:
119591� How to Obtain Microsoft Support Files from Online Services
Microsoft scanned this file for viruses. Microsoft used the most current virus-detection software that was available on the date that the file was posted. The file is stored on security-enhanced servers that help to prevent any unauthorized changes to the file.

↑ Back to the top


Keywords: KB299464, kbhowto, kbdownload, kbdownload

↑ Back to the top

Article Info
Article ID : 299464
Revision : 7
Created on : 11/23/2006
Published on : 11/23/2006
Exists online : False
Views : 325