2015-07-10 61 views
2

我試圖將一些數據上傳到我的Windows Azure存儲帳戶,並在執行代碼時運行到異常。唯一的例外是:將數據上傳到Windows Azure時收到409錯誤

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.

這裏是我的代碼時,Visual Studio一直告訴我,它在不同的地方,每次我試圖打破。

// Retrieve storage account from the connection string. 
     CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString")); 
     // Create the table client. 
     CloudTableClient tableClient = storageAccount.CreateCloudTableClient(); 
     // Create the table if it doesn't exist. 
     CloudTable table = tableClient.GetTableReference("articles"); 
     table.CreateIfNotExists(); 
     // Create a new article entity. 
     Article neumeier = new Article("Israel will strike Iran in the next 5 years", "NeumeierJ.R"); 
     neumeier.User = "NeumeierJ.R"; 
     neumeier.Tagline = "Israel will strike Iran in the next 5 years"; 
     neumeier.UserCredentials = "Founder of Codex.Library"; 
     neumeier.UserEmail = "[email protected]"; 
     neumeier.Author = "Chomsky"; 
     neumeier.AuthorCredentials = "Everyone knows Chomsky..."; 
     neumeier.Category = "LD2015"; 
     neumeier.Citation = "CNN or something like that."; 
     neumeier.Content = "It is inevitable that Israel will attack Iran, or vice versa. In the hotbed of conflict in the MidEast."; 
     // Create the TableOperation that inserts the article entity. 
     TableOperation insertOperation = TableOperation.Insert(neumeier); 
     // Execute the insert operation. 
     table.Execute(insertOperation); 
     // End Azure Test 

我應該使用所有正確的參考和使用語句...

using Microsoft.WindowsAzure; 
using Microsoft.WindowsAzure.Storage; 
using Microsoft.WindowsAzure.Storage.Table; 
using Microsoft.WindowsAzure.Storage.Auth; 
using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Net; 
using System.Net.Http; 
using System.Security.Claims; 
using System.Web.Http; 
using System.Configuration; 

道歉以次充好的格式,第一個問題。任何幫助將是偉大的,謝謝!

+0

「衝突」錯誤表示您嘗試創建的實體已存在於該表中。請檢查一下。 –

回答

2

分區鍵+行鍵一起作爲進入表的主鍵,這個組合必須是唯一的。只要您不違反PK + RK =唯一約束,您就可以在單個分區中擁有幾乎不限數量的行鍵。但我看到你沒有指定分區鍵和行鍵。

相關問題