Microsoft KB Archive/316018

= HOW TO: Update SQL Server Data by Using XML Updategrams =

Article ID: 316018

Article Last Modified on 12/31/2003

-

APPLIES TO


 * Microsoft SQL Server 2000 Standard Edition
 * Microsoft SQL Server 2000 64-bit Edition

-



This article was previously published under Q316018





IN THIS TASK
SUMMARY
 * Requirements
 * Enable a Database for XML Updategram Templates
 * Create the XML Updategram Template
 * Run the XML Updategram Template
 * Verify That the XML Updategram Template Works
 * Other Techniques



SUMMARY
This step-by-step article describes how to update SQL Server data by using XML updategrams.

An updategram is a data structure that you can use to express a change in the data. INSERT, UPDATE, and DELETE commands are represented in an updategram by the difference of the image of the data before and the image of the data after a change.

One way to run an XML updategram is to save the updategram as a file, and then run the file in the URL as a template file.

back to the top

Requirements
The following list outlines the recommended hardware, software, network infrastructure, and service packs that are required:
 * Microsoft Windows NT 4.0 Server, Microsoft Windows 2000 Server, or other Microsoft operating systems that can host Microsoft SQL Server 2000.
 * SQL Server 2000 with Web Release 1.
 * Microsoft Internet Information Services.

This article assumes that you are familiar with the following topics:
 * Extensible Markup Language (XML)

back to the top

Enable a Database for XML Updategram Templates
To enable a database for XML updategram templates:  Create the two folders C:\MyUpdateGram and C:\MyUpdateGram\Template. Create a new SQL Server database, and then give the test database the name MyDatabase.  Create the States table in the MyDatabase database by running the following SQL Statement in SQL Query Analyzer: USE MyDatabase GO CREATE TABLE States (Id INT IDENTITY(1,1), Name NVARCHAR(20)) GO INSERT INTO States (Name) SELECT 'Alabama' INSERT INTO States (Name) SELECT 'AK' INSERT INTO States (Name) SELECT 'Arizona' INSERT INTO States (Name) SELECT 'AR' GO  Run IIS Virtual Directory Management for SQL Server: Click Start, point to Programs, point to Microsoft SQL Server, and then click Configure SQL XML Support in IIS. In the tree view, expand the node that displays the name of the Web server. Right-click Default Web Site, click New, and then click Virtual Directory.</li> On the General tab of the New Virtual Directory Property dialog box, set the Virtual Directory Name to myupdategram, and then set Local Path to C:\MyUpdateGram .</li> On the Security tab of the New Virtual Directory Property dialog box, type the valid connection credentials for the Internet user who will run the updategram.</li> On the Data Source tab of the New Virtual Directory Property dialog box, set SQL Server to the name of the SQL Server, and then set Database to MyDatabase.</li> On the Settings tab of the New Virtual Directory Property dialog box, click to select Allow template queries.</li> On the Virtual Names tab of the New Virtual Directory Property dialog box, click New to add a new virtual name.</li> On the Virtual Names Configuration dialog box, set Virtual Name to template, set Type to template, and then set Path to C:\MyUpdateGram\Template.</li> Click Save to save the template virtual name.</li> Click OK to save the myupdategram virtual directory.</li></ol>

back to the top

Create the XML Updategram Template
Paste the following XML updategram in Notepad, and then save the file as C:\MyUpdateGram\Template\update.xml : <ROOT xmlns:updg=&quot;urn:schemas-microsoft-com:xml-updategram&quot;> <updg:sync> <updg:before> <States updg:id=&quot;1&quot; Name=&quot;AK&quot;/> <States updg:id=&quot;2&quot; Name=&quot;AR&quot;/> </updg:before> <updg:after> <States updg:id=&quot;1&quot; Name=&quot;Alaska&quot;/> <States updg:id=&quot;2&quot; Name=&quot;Arkansas&quot;/> </updg:after> </updg:sync> </ROOT> back to the top

Run the XML Updategram Template
In Microsoft Internet Explorer, type the following URL:

http://localhost/myupdategram/template/update.xml

You may have to substitute &quot;localhost&quot; with the name of your Web server.

back to the top

Verify That the XML Updategram Template Works
In SQL Query Analyzer, switch to the MyDatabase database and then run the query: SELECT * FROM States The XML updategram replaces the abbreviations AK and AR with the full state names for Alaska and Arkansas.

back to the top

Other Technique
You can use the following additional methods to implement XML updategrams:
 * You can configure the virtual directory to allow posted updategrams. When you do so, you can post XML updategrams by using Hypertext Transfer Protocol (HTTP).

-or-
 * You can submit the updategram by using an ActiveX Data Objects (ADO) or OLE DB command.

back to the top

Keywords: kbhowtomaster KB316018

-

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

© Microsoft Corporation. All rights reserved.