BizTalk Utilities CV ,   Jobs ,   Code library  
 
Home Page
SQL XML
.NET SQLXML Performance
Using SqlXmlAdapter in .NET
Using UpdateGrams in .NET
Using OPENXML in .NET
Manually inserting SQLXML data
.NET DataSet Class
SQLXML XPath Queries
.NET XmlTextWriter
SQLXML - XML enabling the Data Layer
.NET SqlXmlException Class
.NET SqlXmlAdapter Classes
.NET SqlXmlParameter Class
.NET SqlXmlCommand Class
.NET Managed Classes
Annotating .NET Updategrams
SQLXML - .NET Updategrams
.NET XPath Queries
SQLXML - Mapping Relationships To XML
SQLXML - Mapping .NET Schemas
.NET & OPENXML
<< SEO
System.XML >>

By :Mark Wilson
I am the creator of TopXML. I am available for international and local (Australia) contracts. I am a Solution Architect/Business Analyst. I have worked in IT in several countries (NZ, Australia, South Africa, UK) building and training teams for government and very large non-governmental organizations. I am ex-Microsoft Consulting Services. I wrote the first book on Microsoft XML published in 2000 called XML Programming with VB and ASP. Most recently I have been building tools for the SEO industry. Ask me for a 37 point SEO health-checkup for your website.
First posted :03/24/2008
Times viewed :242

 

.NET SQLXML Pitfalls

Even though features like XPath queries and Updategrams make SQL Server appear like an XML database we need to realize that it’s still the same old relational database engine under the hood. And the only interface to that relational engine is SQL. SQLXML does a good job to hide the SQL interface, but in some situations SQL’s limitations just come right back in your face to remind you that certain things are not possible. The opposite is true, too. Certain things possible in SQL work differently in XPath. In the following section we will examine some of the limitations to help you stay clear of some of the pitfalls.

Watch Your Case

XPath queries against an annotated schema are case sensitive. While SQL queries are case-insensitive the check of the XPath expression against the schema – like everything else in XML – is case sensitive. If SQLXML cannot validate the XPath expression against the schema it will return an error and not execute the query.

Typing

You cannot include elements mapping to an image, text or ntext type column in the <before> section of an updategram. Elements in a <before> section wind up in the WHERE clause of an UPDATE or a DELETE statement, but SQL Server 2000 cannot compare against values in columns of these data types. Unfortunately you may not realize which elements map to a text type column until you start unit testing.

DateTime values

The W3C standard for XML schemas defines that dateTime values in XML documents be formatted based on the ISO 8601 standard for dates and times. An XML value representing midnight on Christmas Day in the year 2002 in the US central time zone would look like:

<RequiredDate>2002-12-25T00:00:00.000-06:00</RequiredDate>

 This format orders the fields in a way that you can apply alphanumerical a sorting algorithms to sort dateTime values, which is very helpful considering the poor support for date types in XSLT. However, SQL Server does not understand this particular flavor of ISO 8601 formatted dates. If you try to execute an Updategram containing a properly formatted dateTime value you will receive an error telling you that SQL Server does not like your date value – unless you annotate the element in the schema with the datatype annotation from the urn:schemas-microsoft-com:mapping-schema namespace:

<xs:element name="RequiredDate" type="xs:dateTime"

  sql:datatype="dateTime" />

With the annotation in place SQLXML will convert the dateTime value to a format SQL Server recognizes prior to inserting or updating it.

Before and After Updategram sections

SQLXML needs to match up corresponding elements in the <before> and <after> sections of an updategram to determine what type of SQL to generate. It looks for the nodes identified as key-fields in the annotated schema and also for the updategram-specific id attribute in the updategram. If SQLXML fails to match up corresponding elements it generates two unrelated INSERT and DELETE statements to insert the element from the after section and delete the element from the before section. If you fail to catch a bug like this during development you could wind up deleting data from your production database that should not be deleted.

Make sure you always add the key-fields annotation to identify the key columns of a table. Also, if you know your application is going to change values in a key column to add the id attribute to the corresponding elements in your updategram.


Rate this article on a scale of 1 to 10

Your vote :  


 

Recent Jobs

Sr. Software Engineer - Analytics
Immediate Mainframe openings for Ch
Immediate TANDEM-TAL openings for C
Immediate ASP.NET/C# Openings for C
Sr. Software Engineer

View all Jobs (Add yours)
View all CV (Add yours)



conference calling services
water softener
Teleconference
Host Department NOLIMIT Web Hosting
MSN
sunglasses
online fax


    Email TopXML  

Front Page Daily Stuff TopXML Forum XML blogs XML Newsgroups BizTalk Biztalk Utilities Biztalk Utilities Tutorial B2B SAP XML Microsoft .NET Dotnet System XML Soapformatter SQLXML XMLserializer XQuery PHP PHP SimpleXML PHP XML Dom PHP XML RPC PHP XSLT Java Java Java XML Xalan Microsoft ASP ASP Schemas XML SQL Server XML XMLDom XSL XSL Tutorial XSLT Stylesheets General Javascript CSS XHTML WAP