Brandon Lumsden
Brandon Lumsden

Reputation: 79

Export Azure SQL Database to XML File

I have searched Google and this site for about 2 hours trying to gather how to do this and no luck on a way that fits/ I understand. As the title says, I need to export table data to an XML file. I have an Azure SQL database with table data.

Table name: District

Table Columns: Id, name, organizationType, address, etc.

I need to take this data and create a XML file that I can save so that it can be given to others.

I have tried using:

SELECT * 
FROM dbo.District
FOR XML PATH('districtEntry'), ROOT('leaID')

It gives me the data in XML format, but I don't see a way to save it.

Also, there are some functions I need to be able to perform with the data:

Program should have these options:

1) Export all data.

2) Export all rows created or updated since a specified date.

Files should be named in format ENTITY.DATE.XML, as in DISTRICT.20150521.XML (use date in YYYYMMDD format).

This leads me to believe I need to write code other than SQL since a requirement would be to query the table for certain data elements as well.

I was wondering if I would need to download any Database Server Data Tools, write code, and if so, in what language, etc. The XML file creation would need to be automated I believe after every update of the table or after a query.

I am very confused and in need of guidance as I now have almost given up hope. Please let me know if I need to clarify anything. Thank you.

P.S. I would have given pictures but I do not have enough reputation to supply them.

Upvotes: 1

Views: 931

Answers (1)

Dan Field
Dan Field

Reputation: 21661

I would imagine you're looking to write a program in VB.NET or C#, using ADO.NET in either case. Here's an MSDN article with a complete sample of how to connect to and query SQL Azure:

https://msdn.microsoft.com/en-us/library/azure/ee336243.aspx

The example shows how to write the output to the Console, but you could also write the output similarly using something like a StreamWriter to write it to a file.

You could also create a sqlcmd script to do this, following the guidelines here to connect using sqlcmd:

https://msdn.microsoft.com/en-us/library/azure/ee336280.aspx

Alternatively, if this is a process that does not need to be automated or repeated frequently, you could do it using SSMS:

http://azure.microsoft.com/en-us/documentation/articles/sql-database-manage-azure-ssms/

Running your query through SSMS would produce an XML document, which could be saved using File->Save As

Upvotes: 0

Related Questions