使用C#导出Azure数据库

我的C#程序适用于Azure数据库。

我正在使用Microsoft.Rest和Microsoft.Azure.Management库来做一些事情(数据库复制,操作,删除等等)。

我尝试导出Azure数据库,但我无法在C#中找到如何做到这一点。 有谁知道我怎么做,或者直接告诉我一个例子?

根据我的理解,您正在谈论Azure SQL数据库。 我假设您可以将Azure SQL数据库导出到BACPAC文件 。

我尝试导出Azure数据库,但我无法在C#中找到如何做到这一点。

根据您的描述,我检查了Microsoft Azure管理库 ,发现您可以参考以下代码片段将azure sql数据库导出到azure blob存储中:

CertificateCloudCredentials credential = new CertificateCloudCredentials("{subscriptionId}","{managementCertificate}"); var sqlManagement = new SqlManagementClient(credential); var result = sqlManagement.Dac.Export("{serverName}", new DacExportParameters() { BlobCredentials = new DacExportParameters.BlobCredentialsParameter() { StorageAccessKey = "{storage-account-accesskey}", Uri = new Uri("https://{storage-accountname}.blob.core.windows.net/{container-name}") }, ConnectionInfo = new DacExportParameters.ConnectionInfoParameter() { DatabaseName = "{dbname}", ServerName = "{serverName}.database.windows.net", UserName = "{username}", Password = "{password}" } }); 

您可以使用sqlManagement.Dac.GetStatus来检索导出操作的状态。

此外,Microsoft Azure管理库使用导出数据库(经典) ,对于较新的基于资源管理器的REST API,您可以参考此处 。 此外,您可以参考创建存储帐户并利用Microsoft Azure存储资源管理器来管理存储资源,有关详细信息,请参阅此处 。

我找到了问题的解决方案:我必须更新我的Microsoft.Azure.Management.Sql库。 现在,我可以使用这种导出方法:

public static ImportExportResponse Export(此IDatabasesOperations操作,字符串resourceGroupName,字符串serverName,字符串databaseName,ExportRequest参数);