A script to export sql azure databases.

My context for the script in this case.

  1. A bug from the client is reported. A bug that does not cause exception at the back-end nor at the front-end – The font-end simply stops. It does not even freeze. So you do not have any log for this case. Now you are in check ( chess check ).
  2. You need to dump the database from the staging environment ( NO! Not the production! )

The possible solutions :

  1. Go to azure portal and export all the databases needed by hand – click-click-click….a lot.
  2. Make a powershell script and do it really quick. This helps a lot when you do it more then once.

The script :

This is it. If you can elaborate on it and make it automatically restore the dbs in SqlExpress, feel free to post it as a comment.

**UPDATE

I started to encouter strange but persistent error :

PS C:\Windows\system32> Get-AzureSqlDatabase -ConnectionContext $azSqlCtx
WARNING: Client Session Id: ‘…’
WARNING: Client Request Id: ‘…’
Get-AzureSqlDatabase : Internal .Net Framework Data Provider error 6.
At line:1 char:1
+ Get-AzureSqlDatabase -ConnectionContext $azSqlCtx
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : NotSpecified: (:) [Get-AzureSqlDatabase], InvalidOperationException
+ FullyQualifiedErrorId : Microsoft.WindowsAzure.Commands.SqlDatabase.Database.Cmdlet.GetAzureSqlDatabase

There is an article about this error here but I did not find any way to download the fix. Than I opened msdn where GetAzureSqlDatabase is described and used the “ByServerName” method.