Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Export XML from ms sql 2008

0 views
Skip to first unread message

Eric S

unread,
Dec 29, 2009, 12:00:04 AM12/29/09
to
Hi All,

Any idea how to export an xml documnet from ms sql 2008 using vb.net into a
folder some where? I am running an SP that generates the xml already.

Thanks,

Eric

Mark Rae [MVP]

unread,
Dec 29, 2009, 5:25:42 AM12/29/09
to
"Eric S" <xxx_n...@Hotmail.com> wrote in message
news:eRm6NPEi...@TK2MSFTNGP06.phx.gbl...

> Any idea how to export an xml documnet from ms sql 2008 using vb.net into
> a folder some where? I am running an SP that generates the xml already.

http://msdn.microsoft.com/en-us/library/system.io.file.createtext.aspx


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Gregory A. Beamer

unread,
Dec 29, 2009, 11:12:56 AM12/29/09
to
"Eric S" <xxx_n...@Hotmail.com> wrote in
news:eRm6NPEi...@TK2MSFTNGP06.phx.gbl:

> Any idea how to export an xml documnet from ms sql 2008 using vb.net
> into a folder some where? I am running an SP that generates the xml
> already.

I would offer something different than Mark:

http://msdn.microsoft.com/en-us/library/system.xml.xmlwriter.aspx


NOTE that this assumes you are getting a full XML document, with root tags,
rather than an XML snippet. SQL Server can do both.

peace and grace,

--
Gregory A. Beamer (MVP)

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

*******************************************
| Think outside the box! |
*******************************************

Mark Rae [MVP]

unread,
Dec 29, 2009, 11:19:18 AM12/29/09
to
"Gregory A. Beamer" <NoSpamM...@comcast.netNoSpamM> wrote in message
news:Xns9CF067A3...@207.46.248.16...

> I would offer something different than Mark:
>
> http://msdn.microsoft.com/en-us/library/system.xml.xmlwriter.aspx

I took from the OP that he had already fetched a well-formed XML document
from SQL Server and simply wanted to know how to save it do disk...

Gregory A. Beamer

unread,
Dec 29, 2009, 11:36:41 AM12/29/09
to
"Mark Rae [MVP]" <ma...@markNOSPAMrae.net> wrote in
news:eGiRsKKi...@TK2MSFTNGP05.phx.gbl:

> I took from the OP that he had already fetched a well-formed XML
> document from SQL Server and simply wanted to know how to save it do
> disk...

I am a bit TOO XML oriented in many cases. LOL

Peace and Grace,

Eric S

unread,
Dec 29, 2009, 11:56:30 AM12/29/09
to
Hi Mark,

Looking at the code in that link, I am not sure!! That means I need to loop
through all lines?
http://msdn.microsoft.com/en-us/library/system.io.file.createtext.aspx

Dim cmd As New SqlCommand()
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "dbo.XML_MenuOptions"

Thanks,

Eric

"Mark Rae [MVP]" <ma...@markNOSPAMrae.net> wrote in message
news:uoMpGFHi...@TK2MSFTNGP06.phx.gbl...

Mark Rae [MVP]

unread,
Dec 29, 2009, 12:01:30 PM12/29/09
to
"Eric S" <xxx_n...@Hotmail.com> wrote in message
news:%23A2QkfK...@TK2MSFTNGP06.phx.gbl...

[please don't top-post]

>>> Any idea how to export an xml documnet from ms sql 2008 using vb.net
>>> into a folder some where? I am running an SP that generates the xml
>>> already.

>> http://msdn.microsoft.com/en-us/library/system.io.file.createtext.aspx

> Looking at the code in that link, I am not sure!! That means I need to
> loop through all lines?

Look at some of the other methods of the file object, e.g.
http://msdn.microsoft.com/en-us/library/ms143356.aspx

Eric S

unread,
Dec 29, 2009, 12:54:18 PM12/29/09
to
Hi Gregory,

Thanks for your reply. Do you know of any sample somewhere?
Another problem is when I ran the SP within the MS SQL 2008 it generates the
XML as a fine file.

Running the below code somehow I am getting an error like this: Invalid at
the top level of the document. Error processing. When tryuing to see the
value of the cmd.CommanText.
But this is an OK file which already used all the time. (Copy and paste from
the ms sql server).

Dim cmd As New SqlCommand()
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "dbo.XML_MenuOptions"

Using ProductWriter As XmlWriter = XmlWriter.Create(cmd.CommandText)

End Using

Thanks,

Eric

Gregory A. Beamer

unread,
Dec 29, 2009, 3:02:12 PM12/29/09
to
"Eric S" <xxx_n...@Hotmail.com> wrote in news:OToH3$KiKHA.2160
@TK2MSFTNGP02.phx.gbl:

> Thanks for your reply. Do you know of any sample somewhere?

After having a "discussion" with Mark, I think this might answer your
question:
http://tinyurl.com/y9trqjr

It is a very simple save to a file from SQL Server XML kind of answer. As
you know you are dealing with valid XML, the addition of the XML classes is
probably overkill.

Eric S

unread,
Dec 29, 2009, 3:35:01 PM12/29/09
to
Thanks Gregory

"Gregory A. Beamer" <NoSpamM...@comcast.netNoSpamM> wrote in message

news:Xns9CF08E81...@207.46.248.16...

0 new messages