Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure Database export with C#

Tags:

c#

azure

My C# programme works with Azure Database.

I'm using Microsoft.Rest and Microsoft.Azure.Management libraries to do some stuff (DB copy, manipulate, delete, etc...).

I try to do an export of an Azure DB, but I can't find how to do that in C#. Does anyone know how I can do that, or direct me to an example ?

like image 899
Cirrus Minor Avatar asked Feb 14 '26 19:02

Cirrus Minor


1 Answers

Based on my understanding, you are talking about Azure SQL database. I assumed that you could Export your Azure SQL database to a BACPAC file.

I try to do an export of an Azure DB, but I can't find how to do that in C#.

According to your description, I checked Microsoft Azure Management Libraries and found you could refer to the following code snippet for exporting your azure sql database into the azure blob storage:

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}"
    }
});

And you could use sqlManagement.Dac.GetStatus for retrieving the status of the export operation.

Additionally, the Microsoft Azure Management Libraries uses Export Database (classic), for newer resource manager based REST API, you could refer to here. Moreover, you could refer to create a storage account and leverage Microsoft Azure Storage Explorer for a simple way to manage your storage resources, for more details, you could refer to here.

like image 55
Bruce Chen Avatar answered Feb 17 '26 07:02

Bruce Chen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!