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.


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'
GONote: You need to provide the SAS token value starting from sv= and don’t include the ?.
You can check out the screenshot below.

You may also like the articles below.
- Generate SAS and connection string greyed out
- A Backup device of type URL was specified without a Credential, Backup/Restore operation cannot proceed.

I am Rajkishore, and I am a Microsoft Certified IT Consultant. I have over 14 years of experience in Microsoft Azure and AWS, with good experience in Azure Functions, Storage, Virtual Machines, Logic Apps, PowerShell Commands, CLI Commands, Machine Learning, AI, Azure Cognitive Services, DevOps, etc. Not only that, I do have good real-time experience in designing and developing cloud-native data integrations on Azure or AWS, etc. I hope you will learn from these practical Azure tutorials. Read more.
