Microsoft KB Archive/299464

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

Article ID: 299464

Article Last Modified on 11/23/2006

-

APPLIES TO


 * Microsoft BizTalk Server 2000 Standard Edition

-



This article was previously published under Q299464



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.



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:

https://partner.microsoft.com/global/30000104

For more information about the support options that are available and about how to contact Microsoft, visit the following Microsoft Web site:

http://support.microsoft.com/default.aspx?scid=fh;EN-US;CNTACTMS

Steps to Create an AIC in Microsoft Visual Basic to Parse an XML Document into SQL Server 2000
  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  Start Visual Basic 6.0, and then create a new ActiveX DLL project. 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)</ul> </li>  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(&quot;MSXML2.DOMDocument&quot;) xmlDOM.async = False xmlDOM.LoadXML loadtotable Set cn = CreateObject(&quot;adodb.connection&quot;) cn.Open &quot;Provider=sqloledb; Data Source=(local);Initial Catalog=master;&quot;, &quot;sa&quot;, &quot;&quot; Set cmd = CreateObject(&quot;adodb.command&quot;) cmd.ActiveConnection = cn   cmd.CommandType = adCmdStoredProc cmd.CommandText = &quot;ReloadNews&quot; cmd.Parameters.Append cmd.CreateParameter(&quot;@doc&quot;, adChar, adParamInput, Len(xmlDOM.xml), xmlDOM.xml) cmd.Execute If Err.Number <> 0 Then loadtotable = &quot;error&quot; 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 &quot;Provider=sqloledb; Data Source=(local);Initial Catalog=master;&quot;, &quot;sa&quot;, &quot;password&quot; </li> Rename the class to loadtotable, save the project as Loadtotable.vbp , and then compile and make Loadtotable.dll.</li> Register the DLL on the BizTalk Server computer. (Type regsvr32 loadtotable.dll from a command prompt.)</li> 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.</li> Click to expand the Component Services MMC snap-in, and continue expanding until you reach COM+ Applications.</li> Right-click COM+ Applications, click New, click Application, and then click Next.</li> Click Create an empty application.</li> Enter a name for the application, and then click Next.</li> Click the This user: radio button and type in the username and password for the account that you want this application to run under.</li> Click Finish.</li> Navigate through the list of COM+ applications and expand your newly created application.</li> Right-click the Components folder for this application, click New, click Component, and then click Next.</li> 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.</li></ol>

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:

News.exe

The News.exe file contains the following files:

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.

Keywords: kbdownload kbdownload kbhowto KB299464

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.