title: Azure Table Storage throwing exception on Insert: (409) Conflict
body: <p>I'm using Azure Table Storage to log visitor information from my MVC app, but it sometimes throws the following exception:</p>
  
  <pre><code>[WebException: The remote server returned an error: (409) Conflict.]
     System.Net.HttpWebRequest.GetResponse() +1399
     Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync(RESTCommand`1 cmd, IRetryPolicy policy, OperationContext operationContext) in c:\Program Files (x86)\Jenkins\workspace\release_dotnet_master\Lib\ClassLibraryCommon\Core\Executor\Executor.cs:677
  
  [StorageException: The remote server returned an error: (409) Conflict.]
     Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync(RESTCommand`1 cmd, IRetryPolicy policy, OperationContext operationContext) in c:\Program Files (x86)\Jenkins\workspace\release_dotnet_master\Lib\ClassLibraryCommon\Core\Executor\Executor.cs:604
     Microsoft.WindowsAzure.Storage.Table.TableOperation.Execute(CloudTableClient client, CloudTable table, TableRequestOptions requestOptions, OperationContext operationContext) in c:\Program Files (x86)\Jenkins\workspace\release_dotnet_master\Lib\ClassLibraryCommon\Table\TableOperation.cs:44
  </code></pre>
  
  <p>It seems to happen when I first visit the website after a period of inactivity, then when I hit refresh, the page loads and every click from then on is fine.</p>
  
  <p>Here is the part of the code that's causing the exception:</p>
  
  <pre><code>  var visit = new TrackerVisitEntity(id, url, referer);
    var insertOperation = TableOperation.Insert(visit);
    _table.Execute(insertOperation);
  </code></pre>
  
  <p><strong>Update</strong></p>
  
  <p>As identified in the comments AND both answers below, the problem is that sometimes the page is loaded twice in quick succession, and I'm using a GUID (unique to the user) as the partition key, and the current datetime as the row key, so this is causing duplicate entities and causing the exception.</p>
  
  <p>Although Amor's answer was more indepth, Dogu's simple solution was the one I used, so I marked his correct.  Thanks everyone.</p>