DOWNLOAD THE CODE:
Download the Code 16135.zip

SQL Server 2000's new updategrams capability lets you use XML documents to update your databases

The new XML for SQL Web Release supports XML documents called updategrams, which let you use XML across HTTP to update your SQL Server 2000 databases. Updategrams contain special tags that work with SQL Server's IIS support to insert, update, and delete rows in a SQL Server table. Middle-tier agents such as Web applications and n-tier application components that post changes to the database server typically generate the XML updategrams and send them to the SQL Server system across HTTP. You can use updategrams much as you use XML templates, which let you execute SQL statements to update SQL Server databases. However, with updategrams, you use only XML documents to update SQL Server databases—you don't need SQL statements. (For more information about XML templates, see Dan Fox, "ADO and XML," December 2000, and Paul Burke, "XML and SQL Server 2000," May 2000.) Let's walk through how you configure SQL Server 2000's IIS support to enable updategrams, then look at sample updategrams that insert, update, and delete information in a SQL Server database.

Configuring Updategram Support
To use updategrams, you must install the XML for SQL Web Release, which you can download from the Microsoft Web site at http://msdn.microsoft.com/downloads/default.asp. (For more information about the Web Release, see the sidebar "Installing the XML for SQL Web Release," page 67.) After you've installed the Web Release, you can use the IIS Virtual Directory Management for SQL Server administrative tool to configure support for updategrams. You run the administrative tool from Start, Programs, SQL Server, Configure SQL XML Support in IIS.

IIS Virtual Directory Management for SQL Server lets you define and register a new virtual directory on the computer that is running IIS. This new IIS virtual directory defines a connection between IIS and an instance of SQL Server. After starting the IIS Virtual Directory Management for SQL Server tool, right-click the Default Web Site entry and select New Virtual Directory from the pop-up menu. Figure 1, page 66, shows the resulting SQLXMLObjects Properties dialog box.

On the General tab, specify the name of the IIS Virtual Directory and the path to the files that will reside on that virtual directory. Figure 1 shows the Virtual Directory Name set to SQLXMLObjects and the path set to c:\inetpub\wwwroot\SQLXMLObjects. Now, click the Security tab to display the security configuration dialog box that Figure 2 shows.

The Security tab lets you set the authentication options that the SQL Server XML SQLISAPI DLL uses to connect to SQL Server. This DLL passes incoming HTTP requests to the OLE DB Provider for XML, which IIS uses to connect to SQL Server. You have three basic security options for Web-client authentication: Anonymous authentication, Basic authentication, and Integrated Windows authentication. Selecting the Always Log on as radio button, as Figure 2 shows, sets up Anonymous access, which is typically the best choice for Internet access to SQL Server. Anonymous access uses the same security setting—either a shared Windows NT login or a SQL Server login—for the entire virtual directory. Basic authentication specifies a fixed SQL Server login ID to use for access, but the Web client passes this login across the network in clear text. Thus, Basic authentication isn't suited for Internet connections unless you associate it with a Secure Sockets Layer (SSL) connection. Integrated Windows authentication is good for intranet implementations in which the Windows network ID is available, but Integrated Windows security isn't typically useful for Internet connections because you can't pass NT authentication information across the Internet outside your domain. After selecting the type of authentication you want to use, click the Data Source tab to display the dialog box that Figure 3 shows.

You use the Data Source tab to specify the SQL Server system that you want to service the virtual directory. If IIS is running on the same system as SQL Server, you can specify the value (local). Otherwise, you must enter the name of a SQL Server instance. Figure 3 shows the virtual directory associated with the SQL Server system teca4 and shows the default database set to pubs. Now, click the Settings tab to display the IIS Virtual Directory Management dialog box that Figure 4 shows.

The Settings tab lets you control the type of SQL Server access permitted from the virtual directory. To allow updategram execution, you must select the Allow template queries check box, which lets users either execute SQL statements stored in XML template files or run XML updategrams located in the server's virtual templates directory. Notice in Figure 4 that the Allow posted updategrams option, which you might expect to appear selected, is clear. If you select this option, you're allowing the execution of only updategrams and prohibiting the execution of standard XML template queries. Clicking the Virtual Names tab displays the dialog box that Figure 5 shows.

The Virtual Names tab lets you create new virtual directories that the Web client uses to locate XML templates, XML schema, and XPath queries. To create a new virtual name, select from the Type drop-down box the object type to apply to the path, then click New, which lets you enter the virtual directory name followed by the path to the system on which the files will be stored. Figure 5 shows that you'll store templates and updategrams in a virtual directory called templates (you don't need a separate virtual directory for updategrams; you store them along with templates or schemas) and that you'll store the physical template files in the c:\inetpub\wwwroot\SQLXMLObjects\templates subdirectory.

   Prev. page   [1] 2     next page



You must log on before posting a comment.

If you don't have a username & password, please register now.

Reader Comments

I think that this was a great article; this is something that I've been looking foward to. ADO support for updategrams is something else I am curious about. My concern is security. I suppose that I have to wonder if the IIS Virtual Directory Management for SQL Server tool settings is contained inside the(an) IIS Metabase? And how do these settings affect the ADO implementation--if there is a way to access ADO?

David Buchanan

How will UPDATEGRAMS fit in with .NET? Installing .NET removes IIS. In the meantime, this is an excellent new feature that I will be implementing straight away.

James Speer

For the insert and the delete everything is OK but when I try the update, I get an error message from OLE DB. Why ??? Anybody has experienced the same thing ??? Please help !!!

Alex Michaud

This was a good article, but I'm wondering how this is done with parameters in .NET. I've been trying to do it, but so far I haven't had any success. The SQLXML Managed Classes are good, but the parameter class doesn't seem to want to work properly. I'm not sure if this has something to do with IIS or if it's SQLXML itself. I'd love to see an example of passing a parameter to an updategram with the .NET SQLXML Managed Classes.

Melissa

 
 

ADS BY GOOGLE