Backup/Restore to URL device error

I encountered this error while running the SQL script to take the backup of the SQL database to the Azure Blob storage.

Backup/Restore to URL device error: Error while decoding the storage key.

First, let us see the reason for this error.

Reason

This error occurred because I appended the? to the SAS token value in my SQL script, which was wrong.

Backup/Restore to URL device error
Error while decoding the storage key.

Solution

The script should be like below

IF NOT EXISTS (SELECT * FROM sys.credentials   
               WHERE name = 'https://demostoragesql5.blob.core.windows.net/mynewdb')  
CREATE CREDENTIAL [https://demostoragesql5.blob.core.windows.net/mynewdb] 
  WITH IDENTITY = 'SHARED ACCESS SIGNATURE',  
  SECRET = '?sv=2019-12-12&ss=b&srt=c&sp=rwdlacx&se=2021-01-13T14:53:51Z&st=2021-01-12T06:53:51Z&spr=https&sig=3hnMPXIytoxR4%2FIvEiOc1n8cibMVUHsHAcneucfDe3s%3D';


BACKUP DATABASE TSINFODB   
TO URL = 'https://demostoragesql5.blob.core.windows.net/mynewdb/TSINFO123.bak' 
GO

Note: You need to provide the SAS token value starting from sv= and don’t include the ?.

You can check out the screenshot below.

Backup/Restore to URL device error: Error while decoding the storage key

You may also like the articles below.

Azure Virtual Machine

DOWNLOAD FREE AZURE VIRTUAL MACHINE PDF

Download our free 25+ page Azure Virtual Machine guide and master cloud deployment today!