1

当我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; }
    }
4

1 回答 1

1

哦,看起来您对 AddObject 的第一个参数是错误的?它应该是“音乐”,即您的表的名称,但如果要相信参数名称,那么您似乎在传递一个随机字符串。

于 2012-06-05T06:17:52.913 回答