Skip to content

Get the most out of MSSQL !

Consultant & Trainer for all things MSSQL

  • Home
  • Company
  • Business Intelligence
  • Simply Better Business

Exception Message: The client could not finish the operation within specified timeout. Killing the lease on a file in Azure BLOB

Posted on January 22, 2015March 20, 2021 by jayanth.kurup

Exception Message: The client could not finish the operation within specified timeout.

When backing up a database to the cloud if the network connectivity is slow or if the database backup operation was halted in between then the blob (backup file) remains locked in the Azure storage space since the operations didn’t complete. In such cases the DBA needs to clean up such unwanted and incomplete backups but won’t be able to since the lease is still active on the blob file. Very similar to how an Xclusive lock is acquired on the data page. Until this lock/ lease is released the file remains in the blob.

You can connect to the azure blob storage account in order to check if the database backup file has an active lease on it.

In this case we cannot delete the file until the lease is released. The solution is to run the power shell script below

Step 1 :- Open Notepad and copy paste the below content and save the file with a ps extension

--WARNING! ERRORS ENCOUNTERED DURING SQL PARSING!
param([Parameter(Mandatory=$true)] [string] $STORAGEACCOUNT, [Parameter(Mandatory=$true)] [string] $STORAGEKEY, [Parameter(Mandatory=$true)] [string] $BLOBCONTAINER, [Parameter(Mandatory=$true)] [string] $STORAGEASSEMBLYPATH) # Well known

RESTORE Lease ID $RESTORELEASEID = "BAC2BAC2BAC2BAC2BAC2BAC2BAC2BAC2" # LOAD the storage assembly without locking the FILE
FOR the duration OF the PowerShell session $BYTES = [System.IO.File]::ReadAllBytes($STORAGEASSEMBLYPATH) [System.Reflection.Assembly]::LOAD ($BYTES) $CRED = New - OBJECT 'Microsoft.WindowsAzure.Storage.Auth.StorageCredentials' $STORAGEACCOUNT
    ,$STORAGEKEY $CLIENT = New - OBJECT 'Microsoft.WindowsAzure.Storage.Blob.CloudBlobClient' "https://$storageAccount.blob.core.windows.net"
    ,$CRED $CONTAINER = $CLIENT.GetContainerReference($BLOBCONTAINER) #list ALL the blobs $ALLBLOBS = $CONTAINER.ListBlobs() $LOCKEDBLOBS = @() # filter blobs that are have Lease STATUS AS "locked" foreach($BLOB IN $ALLBLOBS) { $BLOBPROPERTIES = $BLOB.Properties

IF ($BLOBPROPERTIES.LeaseStatus - eq "Locked") { $LOCKEDBLOBS += $BLOB } }
    IF ($LOCKEDBLOBS.Count - eq 0) { Write - Host " There are no blobs with locked lease status" }
        IF ($LOCKEDBLOBS.Count - gt 0) { write - host "Breaking leases" foreach($BLOB IN $LOCKEDBLOBS) { try { $BLOB.AcquireLease($NULL, $RESTORELEASEID, $NULL, $NULL, $NULL) Write - Host "The lease on $($blob.Uri) is a restore lease" } catch [Microsoft.WindowsAzure.Storage.StorageException] {
            IF ($_. Exception.RequestInformation.HttpStatusCode - eq 409) { Write - Host "The lease on $($blob.Uri) is not a restore lease" } } Write - Host "Breaking lease on $($blob.Uri)" $BLOB.BreakLease($( New - TimeSpan)
                ,$NULL
                ,$NULL
                ,$NULL ) | OUT - NULL } }

Step 2:- Run the powershell script in Powershell 3.0 via command prompt using the command below

powershell -noexit “& “”Path of the powerhsell file clearlease.ps1″””

Step 3:- Enter the details required which include the storageid , key , container name and the path for the azure Storage assembly path (usually found in Binn folder of SQL install path).

Step 4:- Wait until the lease is expired you should see messages like

Breaking lease on URL for strorage account container.

Please Consider Subscribing

Subscribe

CategoriesAzure, DatabasesTagsaccount, administration, age, AI, allBlobs, Analysis Services, AWS, Azure, Azure blob Storage account, Azure storage, Azure storage space, azurewebsites, backup, backup file, Bangalore, Bengaluru, BigData, blob, blob storage, BLOB storage account, blobContainer, blobProperties, BLR, break, Business Intelligence, bytes, case, check, clean, client, Cloud, command, Consultant, Consulting, container, copy, copy paste, Core, Corporate, count, courier, cred, credential, Data, data page, database, dba, detail, development, duration, Enabled Business Solutions, enabledbusiness, exception, Exception Message, expert, extension, file, Finish, folder, foreach, form, format, host, INCLUDE, index, India, info, information, Jayanth, key, Kurup, lease, lie, lock, lockedBlobs, message, microsoft, Migration, ML, ms sql server, MSBI, MSSQL, MYSQL, name, need, network, network connectivity, New-Object, note, NULL, object, operation, Oracle, parameter, path, png, power, power pivot, Power Query, PowerApps, PowerBI, Powershell, powershell script, Python, RAM, RDBMS, red, reference, reflection, release, Remote, request, restore, restore lease, restoreLeaseId, run, script, security, session, site, solution, space, sql, SQL 2000, SQL 2005, SQL 2008, sql 2008 r2, sql 2012, SQL 2014, SQL 2016, SQL 2017, SQl 2019, SSAS, SSIS, SSMS, SSRS, status, step, storage, storage account, storageAccount, storageAssemblyPath, storageKey, string, sys, T-SQL, tab, tie, timeout, tools, trainer, Transact, tuning, Upgrade, uploads, Uri, URL, Very large database, Virtual, virtual machine, visual studio, VM, wait, Web, website, Websites, window, windows, WindowsAzure, work, Write-Host

jayanth.kurup

This post was written by Jayanth Kurup. A Microsoft SQL Server Consultant and Trainer based out of Bangalore, India. Jayanth has been working on MS SQL Server for over 15 years. He is a performance tuning and Business Intelligence expert. Having worked with companies like Microsoft, DELL, Wells Fargo, Thomson Reuters and many other fortune 100 companies. Some other technologies Jayanth works on include Microsoft Azure, PowerBI, Python and AWS. When he isn’t consulting or training, Jayanth like to travel, paint and read. He is also very active in social causes and the founder of Enabled Business Solutions. Visit his company by clicking the link in the menu or email him directly.

Post navigation

PreviousPrevious post: Installing SQL 2014
NextNext post: Storing the MDF and LDF files of SQL Server on Azure Storage Part 1

The Latest

  • Monty Hall Simulation using T-SQL April 5, 2022
  • Query to quickly profile a column February 7, 2022
  • Outlook 2019 keeps asking for password multiple times December 9, 2021
  • Part 2:- Learning T SQL for beginners – Datatypes September 28, 2021
  • Part 1:- Learning T SQL for beginners- SQL, Tables and Nulls September 27, 2021
  • Query to find execution time of Jobs July 28, 2021
  • A simple script to decapitalize Column names July 19, 2021
  • My personal side effects with Covishield June 27, 2021
  • Setting up and Configuring CUDA, CUDNN and PYTorch for Python Machine Learning. June 3, 2021
  • keras.utils.generic_utils’ has no attribute ‘populate_dict_with_module_objects May 30, 2021

Find By Category

  • Azure
  • Databases
  • Events
  • Performance Tuning
  • PowerBI
  • Uncategorized
  • Website Design

Archive

  • April 2022 (1)
  • February 2022 (1)
  • December 2021 (1)
  • September 2021 (2)
  • July 2021 (2)
  • June 2021 (2)
  • May 2021 (2)
  • April 2021 (5)
  • March 2021 (10)
  • January 2021 (2)
  • November 2020 (2)
  • October 2020 (3)
  • September 2020 (4)
  • August 2020 (6)
  • July 2020 (1)
  • June 2020 (32)
  • May 2020 (18)
  • April 2020 (2)
  • March 2020 (4)
  • February 2020 (5)
  • January 2020 (1)
  • December 2019 (1)
  • November 2019 (14)
  • October 2019 (3)
  • September 2019 (1)
  • July 2019 (3)
  • June 2019 (2)
  • May 2019 (1)
  • April 2019 (2)
  • March 2019 (1)
  • January 2019 (4)
  • December 2018 (2)
  • November 2018 (4)
  • September 2018 (6)
  • August 2018 (2)
  • July 2018 (3)
  • June 2018 (4)
  • May 2018 (1)
  • April 2018 (4)
  • March 2018 (3)
  • February 2018 (3)
  • January 2018 (1)
  • December 2017 (2)
  • November 2017 (4)
  • August 2017 (2)
  • July 2017 (5)
  • May 2017 (1)
  • March 2017 (3)
  • January 2017 (3)
  • December 2016 (2)
  • November 2016 (2)
  • October 2016 (4)
  • September 2016 (1)
  • August 2016 (1)
  • July 2016 (1)
  • June 2016 (1)
  • May 2016 (2)
  • April 2016 (1)
  • March 2016 (14)
  • February 2016 (10)
  • January 2016 (19)
  • December 2015 (3)
  • November 2015 (5)
  • October 2015 (10)
  • September 2015 (9)
  • August 2015 (16)
  • July 2015 (13)
  • June 2015 (4)
  • May 2015 (2)
  • April 2015 (2)
  • March 2015 (7)
  • February 2015 (3)
  • January 2015 (22)
  • December 2014 (1)
  • November 2014 (5)
  • October 2014 (12)
  • September 2014 (5)
  • August 2014 (7)
  • July 2014 (41)
  • June 2014 (9)
  • May 2014 (12)
  • April 2014 (32)

Members Only

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org
Proudly powered by WordPress