简体   繁体   English

将Azure SQL数据库导出到XML文件

[英]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. 我已经在Google和这个网站上搜索了大约2个小时,试图了解如何做到这一点,但没有找到适合/我理解的方式。 As the title says, I need to export table data to an XML file. 如标题所示,我需要将表数据导出到XML文件。 I have an Azure SQL database with table data. 我有一个带有表数据的Azure SQL数据库。

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. 我需要获取这些数据并创建一个我可以保存的XML文件,以便可以将其提供给其他人。

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. 它以XML格式提供了数据,但是我看不到保存数据的方法。

Also, there are some functions I need to be able to perform with the data: 另外,我需要能够对数据执行一些功能:

Program should have these options: 程序应具有以下选项:

1) Export all data. 1)导出所有数据。

2) Export all rows created or updated since a specified date. 2)导出自指定日期以来创建或更新的所有行。

Files should be named in format ENTITY.DATE.XML, as in DISTRICT.20150521.XML (use date in YYYYMMDD format). 文件的格式应为ENTITY.DATE.XML,如DISTRICT.20150521.XML(使用YYYYMMDD格式的日期)。

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. 这使我相信我需要编写除SQL之外的其他代码,因为要求也是要查询表中的某些数据元素。

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. 我想知道是否需要下载任何数据库服务器数据工具,编写代码,如果需要,还可以使用哪种语言编写代码,等等。XML文件的创建将需要自动化,我相信在表的每次更新或查询之后。

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. 谢谢。

PS I would have given pictures but I do not have enough reputation to supply them. 附言:我本来可以提供图片,但是我没有足够的声誉来提供图片。

I would imagine you're looking to write a program in VB.NET or C#, using ADO.NET in either case. 我想您会在两种情况下使用ADO.NET来编写VB.NET或C#程序。 Here's an MSDN article with a complete sample of how to connect to and query SQL Azure: 这是MSDN文章,其中包含有关如何连接和查询SQL Azure的完整示例:

https://msdn.microsoft.com/en-us/library/azure/ee336243.aspx 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. 该示例显示了如何将输出写入Console ,但是您也可以类似地使用StreamWriter类的东西将输出写入文件。

You could also create a sqlcmd script to do this, following the guidelines here to connect using sqlcmd : 您还可以按照此处的指南使用sqlcmd进行连接,以创建sqlcmd脚本来执行此操作:

https://msdn.microsoft.com/en-us/library/azure/ee336280.aspx 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: 另外,如果此过程不需要自动化或经常重复,则可以使用SSMS进行:

http://azure.microsoft.com/en-us/documentation/articles/sql-database-manage-azure-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 通过SSMS运行查询将生成一个XML文档,可以使用File->Save As保存该文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM