?
Solved

vb.net XML SQL

Posted on 2014-03-13
3
Medium Priority
?
389 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 23

Accepted Solution

by:
Ioannis Paraskevopoulos earned 2000 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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

In this article I will describe the Detach & Attach 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.
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

762 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