473,406 Members | 2,710 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

SqlXMLCommand Help?

I noticed an earlier post, Multiple External References in Transform - Background to the problem - Long Post, where the poster referenced an object entitled SqlXmlCommand. I am unable to find this object?

My requirement is thus. Read several tables from sql server 2000 db with the auto xml feature and read them into a single XPathDocument. Each of the tables need to be read as seperate calls and placed in a single XPathDocument. The db fetch can be either a select or stored procedure call.

What is the most efficient way to do this? Please provide an example.

Thanks
Keith
Nov 12 '05 #1
2 5025
Keith,

SqlXmlCommand lives in the Microsoft.Data.SqlXml; namespace.
You need to install Microsoft SQLXML 3.0 Service Pack 2. Which you will find at:-
http://msdn.microsoft.com/library/de.../sqlserver.asp

I don't know how you want to measure efficiency - can be a bit of an interesting problem in an n-tier system.
My preferred route is to ship XML to the client and do as much mangling as sensible their.
This gets complicated with paging and caching strategies of course (!)

I've yet to extend my performance measurements to really come to a solid conclusion about the SQLXML library.
Following my own metrics I want to create XML as early as possible, but process as close to client as possible.
In fact the operation in the earlier post could be a candidate for migration to the client, rather than in the .Net middle tier - But I wanted to learn about the native XML handling.

Stephen
"Keith Chadwick" <kc*******@leewardsystems.com> wrote in message news:eJ**************@TK2MSFTNGP12.phx.gbl...
I noticed an earlier post, Multiple External References in Transform - Background to the problem - Long Post, where the poster referenced an object entitled SqlXmlCommand. I am unable to find this object?

My requirement is thus. Read several tables from sql server 2000 db with the auto xml feature and read them into a single XPathDocument. Each of the tables need to be read as seperate calls and placed in a single XPathDocument. The db fetch can be either a select or stored procedure call.

What is the most efficient way to do this? Please provide an example.

Thanks
Keith
Nov 12 '05 #2
Keith,

The SqlXmlCommand is part of the SQLXML web release for SQL Server [0], but it sounds like you don't need it for your specific purposes.

You can accomplish what you need either with SqlXml or just with the SqlClientCommand's ExecuteXmlReader. You need to write all the tables to the same string or stream and the read the contents of the stream into the XPathDocument.

The code will go something like this:

using System;
using System.IO;
using System.Xml;

StringWriter sw = new StringWriter();
XmlTextWriter tw = new XmlTextWriter( sw );

tw.WriteStartElement( "MyRoot" ); // create a common root for all the tables

myConnection.Open();

XmlReader reader = new SqlCommand("SELECT * from table1 FOR XML AUTO, myConnection).ExecuteXmlReader();
tw.WriteNode( reader ) );
reader.Close();
reader = new SqlCommand("SELECT * from table2 FOR XML AUTO, myConnection).ExecuteXmlReader();
tw.WriteNode( reader ) );
reader.Close();
// Always close the XmlReader when finished.

tw.EndElement(); // close MyRoot
myConnection.Close();

XPathDocument doc = XPathDocument( new StringReader( sw.ToString() ) ); // read the Xml Content from the string

// Do your stuff


The SQLXML code could be more concise and offer you more flexibility, since you could combine and externalize all the SQL statements into a SQLXML template.

The code then would be something like this:

SqlXmlCommand cmd = new SqlXmlCommand( sqlxmlConnectionString );
cmd.CommandType = SqlXmlCommandType.TemplateFile

cmd.CommandText = "mytemplatefile.xml";

// You can use ExecuteToStream if that suits you better

tw.WriteStartElement( "MyRoot" ); // create a common root for all the tables
XmlReader reader = cmd.ExecuteXmlReader();
tw.WriteNode( reader ) );
reader.Close();

For more information and sample code on SQLXML and .NET you can take a look at [1].
It's hard to to say which one's better without knowing more about what other factors come into play
--
HTH
Christoph Schittko [MVP. XmlInsider]
Software Architect, .NET Mentor

[0] http://msdn.microsoft.com/nhp/defaul...300&frame=true
[1] http://www.topxml.com/sqlxml/default.asp
"Keith Chadwick" <kc*******@leewardsystems.com> wrote in message news:eJ**************@TK2MSFTNGP12.phx.gbl...
I noticed an earlier post, Multiple External References in Transform - Background to the problem - Long Post, where the poster referenced an object entitled SqlXmlCommand. I am unable to find this object?

My requirement is thus. Read several tables from sql server 2000 db with the auto xml feature and read them into a single XPathDocument. Each of the tables need to be read as seperate calls and placed in a single XPathDocument. The db fetch can be either a select or stored procedure call.

What is the most efficient way to do this? Please provide an example.

Thanks
Keith
Nov 12 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: Dave | last post by:
After following Microsofts admonition to reformat my system before doing a final compilation of my app I got many warnings/errors upon compiling an rtf file created in word. I used the Help...
6
by: wukexin | last post by:
Help me, good men. I find mang books that introduce bit "mang header files",they talk too bit,in fact it is my too fool, I don't learn it, I have do a test program, but I have no correct doing...
3
by: Colin J. Williams | last post by:
Python advertises some basic service: C:\Python24>python Python 2.4.1 (#65, Mar 30 2005, 09:13:57) on win32 Type "help", "copyright", "credits" or "license" for more information. >>> With...
1
by: Michael Palmer | last post by:
I'm reading xml from SQL Server 2K with VB.net using an XSD schema file and SQLXML 3.0. I have the below code working fine, but I'd like to change the code from reading the schema file from a...
7
by: Corepaul | last post by:
Missing Help Files When I enter "recordset" as the keyword and search the Visual Basic Help index, I get many topics of interest in the resulting list. But there isn't any information available...
5
by: Steve | last post by:
I have written a help file (chm) for a DLL and referenced it using Help.ShowHelp My expectation is that a developer using my DLL would be able to access this help file during his development time...
8
by: Mark | last post by:
I have loaded Visual Studio .net on my home computer and my laptop, but my home computer has an abbreviated help screen not 2% of the help on my laptop. All the settings look the same on both...
10
by: JonathanOrlev | last post by:
Hello everybody, I wrote this comment in another message of mine, but decided to post it again as a standalone message. I think that Microsoft's Office 2003 help system is horrible, probably...
0
by: =?Utf-8?B?Sm9iIExvdA==?= | last post by:
Would it be efficient to use SqlXmlCommand.ExecuteToStream() method of SQLXML Managed Classes than reading node at a time using XmlReader returned by SqlCommand.ExecuteXmlReader() methiod. Data in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.