Solved

vb.net XML SQL

Posted on 2014-03-13
3
376 Views
Last Modified: 2014-03-14
The below function creates an XML document that is then written to disk.  Also below is an T-SQL command that converts part of the XML document into an SQL table.  It all works.  

QUESTION:  Can the step of writing the XML document to disk be skipped and the XML document object be sent directly to the T-SQL statement that is sent to SQL 2008?
    Public Function xCMP() As XDocument

        Return _
         <?xml version="1.0"?>
         <CMPDocument>
             <Title>EPOWERdoc - CMP Document</Title>
             <Client>
                 <DateProcessed><%= Dt2Db(Now()) %></DateProcessed>
                 <CliNo><%= Clino %></CliNo>
                 <CliServerName><%= CliServerName %></CliServerName>
                 <RAMTotal><%= RAMTotal %></RAMTotal>
                 <RAMSQL><%= RAMSQL %></RAMSQL>
                 <LastFDBUpdate><%= LastFDBUpdate %></LastFDBUpdate>
             </Client>
             <CMPData>
                 <%= xDiskDrives %>
                 <%= xVolume %>
                 <%= xExecutables %>
                 <%= xEPDApplicationErrors %>
                 <%= xEventLog %>
             </CMPData>
         </CMPDocument>
    End Function

Open in new window


---------------------------  T-SQL ----------------------------
DECLARE @x xml
SELECT @x = SQLs
FROM OPENROWSET (BULK 'C:\EPD\EPD315\Bin\CMP\1_201403130224.xml', SINGLE_BLOB) AS Solution(SQLs)

DECLARE @hdoc int

EXEC sp_xml_preparedocument @hdoc OUTPUT, @x

SELECT * FROM OPENXML (@hdoc, '/CMPDocument/CMPData/DiskDrives', 2)
WITH (
      [Drive] varchar(500)
      ,TotalSpace varchar(500)
      ,FreeSpace varchar(500)
      )

EXEC sp_xml_removedocument @hdoc

EXEC sp_xml_preparedocument @hdoc OUTPUT, @x

Open in new window

0
Comment
Question by:dastaub
3 Comments
 
LVL 23

Accepted Solution

by:
Ioannis Paraskevopoulos earned 500 total points
ID: 39928464
Hi,

Since SQL has an xml data type, you may add it to the procedure's parameters and then directly pass an xml to the sp instead of writting it to the disk.

For calling it through your program you may check the following link:
http://msdn.microsoft.com/en-us/library/34e4kcbw(v=vs.110).aspx

Giannis
0
 

Author Comment

by:dastaub
ID: 39929567
Thank You
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now