Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getting 409 error when trying to call table.CreateIfNotExists() for the first time

When starting my program for the first time since the associated table has been deleted I get this error:

An exception of type 'Microsoft.WindowsAzure.Storage.StorageException' occurred in Microsoft.WindowsAzure.Storage.dll but was not handled in user code

Additional information: The remote server returned an error: (409) Conflict.

However if I refresh the crashed page the table will successfully create.

Here is the code just in case:

CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
Microsoft.WindowsAzure.CloudConfigurationManager.
GetSetting("StorageConnectionString"));

CloudTableClient tableClient = storageAccount.CreateCloudTableClient();

CloudTable table = tableClient.GetTableReference("tableTesting");
table.CreateIfNotExists();

I don't really understand how or why I'd be getting a conflict error if there's nothing there.

These errors appear elsewhere in my code as well when I'm working with blob containers, but I can't reproduce them as easily.

like image 355
Slicedbread Avatar asked Aug 05 '14 14:08

Slicedbread


1 Answers

If you look at the status codes here: http://msdn.microsoft.com/en-us/library/azure/dd179438.aspx, you will notice that you get 409 error code in two scenarios:

  1. Table already exists
  2. Table is being deleted

If I understand correctly, table.CreateIfNotExists() only handles the 1st situation but not the 2nd one. Please check if that is not the case in your situation. One way to check this would be to see details of Storage Exception. Somewhere you should get the code which would match with the link I mentioned above.

Also one important thing to understand is that when you delete the table, it is actually marked for deletion and is actually deleted through a background process (much like garbage collection). If you try to create a table between these two steps, you will get the 2nd error.

like image 113
Gaurav Mantri Avatar answered Oct 04 '22 23:10

Gaurav Mantri