使用 C# 导出 Azure 数据库

2024-01-26

我的 C# 程序可与 Azure 数据库配合使用。

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

我尝试导出 Azure DB,但找不到如何在 C# 中执行此操作。 有谁知道我该怎么做,或者指导我举一个例子?


根据我的理解,你说的是Azure SQL数据库。我以为你可以将 Azure SQL 数据库导出到 BACPAC 文件 https://learn.microsoft.com/en-us/azure/sql-database/sql-database-export.

我尝试导出 Azure DB,但找不到如何在 C# 中执行此操作。

根据你的描述,我查了一下Microsoft Azure 管理库 https://www.nuget.org/packages/Microsoft.WindowsAzure.Management.Libraries/发现您可以参考以下代码片段将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 管理库使用导出数据库(经典) https://msdn.microsoft.com/en-us/library/azure/dn781282.aspx,对于较新的基于资源管理器的REST API,您可以参考here https://learn.microsoft.com/en-us/rest/api/sql/databases%20-%20import%20export#Databases_Export。另外,你可以参考创建存储帐户 https://learn.microsoft.com/en-us/azure/storage/storage-create-storage-account#create-a-storage-account和杠杆微软Azure存储资源管理器 http://storageexplorer.com/对于管理存储资源的简单方法,更多详细信息,您可以参考here https://learn.microsoft.com/en-us/azure/vs-azure-tools-storage-explorer-blobs.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用 C# 导出 Azure 数据库 的相关文章

随机推荐