The correct way to delete and recreate a Windows Azure Storage Table = Error 409 Conflict - Code : TableBeingDeleted

喜你入骨 提交于 2019-12-03 22:56:50

From MSDN: "Note that deleting a table is likely to take at least 40 seconds to complete. If an operation is attempted against the table while it was being deleted, the service returns status code 409 (Conflict), with additional error information indicating that the table is being deleted."

The only way to deal with this is to create a table with a different name. This could be as simple as appending a timestamp or GUID to your name. Just be careful to clean up your garbage.

huha

If you need to use the same table name you can use an extension method:

public static class StorageExtensions
{
    public static bool SafeCreateIfNotExists(this CloudTable table, TableRequestOptions requestOptions = null, OperationContext operationContext = null)
    {
        do
        {
            try
            {
                return table.CreateIfNotExists(requestOptions, operationContext);
            }
            catch (StorageException e)
            {
                if ((e.RequestInformation.HttpStatusCode == 409) && (e.RequestInformation.ExtendedErrorInformation.ErrorCode.Equals(TableErrorCodeStrings.TableBeingDeleted)))
                    Thread.Sleep(1000);// The table is currently being deleted. Try again until it works.
                else
                    throw;
            }
        } while (true);
    }
}

WARNING! Be careful when you use this approach, because it blocks the thread. And it can go to the dead loop if third-party service (Azure) keeps generating these errors. The reason for this could be table locking, subscription expiration, service unavailability, etc.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!