3
votes

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.'

5

5 Answers

4
votes

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

2
votes

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

0
votes

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

0
votes

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

0
votes

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.