SQL Server with Mr. Denny

Aug 24 2016   4:00PM GMT

Releasing a Page Blob Lease in Azure

Denny Cherry Denny Cherry Profile: Denny Cherry

Tags:
Azure

2478229521_f40dbba2b4_bSometimes when firing up VMs or moving VMs from the page or blob store you’ll get an error that there is still a lease on the file.  To solve this you need to release the lease. But waiting won’t do the trick, as the leases don’t have an expiration date.

I found some VB.NET code online that with some tweaking (with the help of Eli Weinstock-Herman and Christiaan Baes) I was able to get to release the lease.

The first thing you’ll need is Visual Studio 2015.  You’ll also need the Azure Storage Client.

Once those are both installed you need to create a new VB.NET project.  I used a command line app.

Then put this code in the app. Replace the placeholders that I show in {} with the actual values from your Azure account. Then compile and run the code. The lease will be released.

Imports Microsoft.WindowsAzure.Storage.Auth
Imports Microsoft.WindowsAzure.Storage.Blob
Imports Microsoft.WindowsAzure.Storage
Module Module1

Sub Main()
Dim Cred As New StorageCredentials(“{StorageAccount}”, “{StorageAccountKey}”)
Dim sourceBlobClient As New CloudBlobClient(New Uri(“http://{StorageAccount}.blob.core.windows.net/”), Cred)

Dim sourceContainer As CloudBlobContainer = sourceBlobClient.GetContainerReference(“{ContainerName}”)

Dim sourceBlob As CloudPageBlob = sourceContainer.GetBlobReferenceFromServer(“{FileName}”)

Dim breakTime As TimeSpan = New TimeSpan(0, 0, 1)

sourceBlob.BreakLease(breakTime)

End Sub

End Module

Sadly, short of doing this I haven’t been able to find an easier way of doing this.

Denny

 Comment on this Post

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

Share this item with your network: