当我DataServiceRequestException
尝试将实体保存到天蓝色表时出现异常。它发生在这一行_myContext.SaveChangesWithRetries();
我试图谷歌看看问题可能是什么。但找不到任何答案。
任何人都知道问题可能是什么?
存储创建者
public CloudTableClient GetMusicClient() {
//retrieve connection string from settings
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
RoleEnvironment.GetConfigurationSettingValue("StorageConnectionString"));
//create table client
CloudTableClient tableClient = storageAccount.CreateCloudTableClient();
//create table if doesn't exist
string tableName = "music";
tableClient.CreateTableIfNotExist(tableName);
return tableClient;
}
网络API
public Music PostMusic(string genre, string artist, string random)
{
CloudTableClient _myTableClient = _myTableRepo.GetMusicClient();
TableServiceContext _myContext = _myTableClient.GetDataServiceContext();
Music music = new Music(genre, artist);
music.Score = "10";
music.Year = "2012";
music.Random = random;
try
{
_myContext.AddObject(random, music);
_myContext.SaveChangesWithRetries();
}
catch (StorageClientException e)
{ }
catch (DataServiceRequestException e)
{
System.Diagnostics.Debug.WriteLine(e.StackTrace);
}
return music;
}
堆栈跟踪
An error occurred while processing this request.
at Microsoft.WindowsAzure.StorageClient.Tasks.Task`1.get_Result()
at Microsoft.WindowsAzure.StorageClient.Tasks.Task`1.ExecuteAndWait()
at MyWebAPI.Controllers.ValuesController.PostMusic(String genre, String artist, String random) in C:\MyWebAPI\MyWebAPI\Controllers\ValuesController.cs:line 61
音乐.cs
public class Music : TableServiceEntity
{
public Music(string genre, string artist)
{
this.PartitionKey = genre;
this.RowKey = artist;
}
public Music() {}
public string Score { get; set; }
public string Year { get; set; }
public string Random { get; set; }
}