3

I deleted a Virtual Machine and its associated cloud service and virtual network but I can't delete its storage account.

I got this error:

Failed to delete storage account messega. Unable to delete storage account 'messega':

'Storage account messega has some active image(s) and/or disk(s), e.g. messega-messega-os-1449504882530. Ensure these image(s) and/or disk(s) are removed before deleting this storage account.'.

I went to Storage accounts (classic)>>Services--Blobs>>Containers--vhds and tried to delete the storage container 'vhds': messega-messega-os-1449504882530 but I got this new error:

Failed to delete storage container 'vhds'. Error: 'There is currently a lease on the container and no lease ID was specified in the request.'

Sarjan Desai
  • 3,683
  • 2
  • 19
  • 32
ysn_chy
  • 71
  • 1
  • 5

5 Answers5

4

deleting the disks can be done via the previous version of the portal manage.windowsazure.com Virtual Machines -> Disks

ysn_chy
  • 71
  • 1
  • 5
2

It's a common error. Your vhd is in this storage account, that's why you can't remove it, without delete the vhd.

https://stackoverflow.com/a/10969013/1384539

Community
  • 1
  • 1
Thiago Custodio
  • 17,332
  • 6
  • 45
  • 90
  • Hi Thiago! Thanks for your reply I went to Storage accounts (classic)>>Services--Blobs>>Containers--vhds and tried to delete the storage container 'vhds': messega-messega-os-1449504882530 but i got this new error : Failed to delete storage container 'vhds'. Error: 'There is currently a lease on the container and no lease ID was specified in the request.' – ysn_chy Dec 08 '15 at 11:05
  • 1
    Yeap, you're trying to delete the blob first, but you need to remove the disk, then you can remove the blob. http://blogs.msdn.com/b/mast/archive/2013/02/05/iaas-unable-to-delete-vhd-there-is-currently-a-lease-on-the-blob.aspx – Thiago Custodio Dec 08 '15 at 11:09
  • you are right but there is no section 'Disks' in the virtual Machine section with this new interface portal.azure.com. in the previous interface: All Disks resources are found on the Management Portal under: Virtual Machines -> Disks ###Any ideas where that could be ? – ysn_chy Dec 08 '15 at 11:16
  • can't you use the previous version of the portal? Another option, delete from powershell https://msdn.microsoft.com/en-us/library/azure/dn495255.aspx – Thiago Custodio Dec 08 '15 at 11:27
0

If lease on your .vhd keeps annoying you, you may use a tool than enables to break the lease such as Azure Management Studio or use code to break it :

        var azureStorageConnectionString = ConfigurationManager.AppSettings["AzureStorage.ConnectionString"];
        var blobFileToDelete= ConfigurationManager.AppSettings["BlobFileToDelete.Name"];  

        var account = CloudStorageAccount.Parse(azureStorageConnectionString);

        // Create the blob client using the Accounts above
        var client = account.CreateCloudBlobClient();
        // Retrieve reference to a previously created container
        // Rename "vhds" as needed.  Can be used to read from any container.
        var container = client.GetContainerReference("vhds");

        var blob = container.GetBlockBlobReference(blobFileToDelete);

        if (blob.Properties.LeaseStatus==Microsoft.WindowsAzure.Storage.Blob.LeaseStatus.Locked) 
        { 
            try 
            { 
                Console.WriteLine("Breaking leases on {0} blob.",blobFileToDelete); 
                // Create Timespan to allow the Lease to remain, in this case 1 second
                TimeSpan breakTime = new TimeSpan(0, 0, 1);

                blob.BreakLease(breakTime, null, null, null); 
                Console.WriteLine("Successfully broken lease on {0} blob.",blobFileToDelete); 
            } 
            catch (StorageException ex ) 
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine("Failed to break lease on {blobName} blob.", blobFileToDelete); 
            } 
        } 
        else 
        {
            Console.WriteLine("The {0} blob's lease status is unlocked.", blobFileToDelete); 
        } 
        Console.ReadLine();

Hopes this helps Best regards Stéphane

stephgou
  • 199
  • 2
0

You need to Use the Azure Storage Explorer tool and check for the content of the container most of the time it will not be empty

ZeeMoussa
  • 173
  • 10
0

I tried all these things with no luck. The answer for me was to download http://storageexplorer.com/ and from this tool I was able to delete the necessary files.

Dale Fraser
  • 4,623
  • 7
  • 39
  • 76