Home > Asp.net > Backup and restore SQL Database to Azure Blob Storage Service in C#

Backup and restore SQL Database to Azure Blob Storage Service in C#

Microsoft Azure Blob Storage is a scalable, online cloud data storage service that stores data blobs in containers.
This article helps you understand how to write backups to and restore from the Azure Blob Storage Service and to do so we will create an Azure Blob Container, credentials for accessing the storage account, writing a backup to the blob service, and then performing a simple restore.The backup file will be stored in .bak format.

Add following namespace to work with Azure Storage and Sql:
1.using Microsoft.Azure;
2.using Microsoft.WindowsAzure.Storage;
3.using Microsoft.WindowsAzure.Storage.Blob;
4.using System.Data;
5.using System.Data.SqlClient;

Create connection in web config:

Backup:
To take backup on Blob storage follow following steps:
1. Create credential with blob account name and secret.
2. Set database to full recovery.
3. Take database backup in the blob with credentials.

Restore:

To restore the .bak file stored on blob, follow following steps:
1.Download .bak file from azure blob storage to local machine.
2.Get logical name of the file to be restored.
3.Restore the .bak file on database.

Look into Azure Blob Storage for connection and connection string:

This Article is TAGGED in , , , , , . BOOKMARK THE permalink.

2 thoughts on “Backup and restore SQL Database to Azure Blob Storage Service in C#

  1. Thanks for sharing your knowledge.
    I want to implement this for multi tenant application my tenant database is in single database.

    Any Suggestion ?

    Thanks,
    Bharat Prajapat

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">