【问题标题】:Write Azure Table Storage - Different behaviour local and cloud编写 Azure 表存储 - 本地和云的不同行为
【发布时间】:2020-01-15 10:07:47
【问题描述】:

我有一个简单的 Azure 函数,它定期将一些数据写入 Azure 表存储。

var storageAccount = new CloudStorageAccount(new Microsoft.WindowsAzure.Storage.Auth.StorageCredentials("mystorage","xxxxx"),true);

var tableClient = storageAccount.CreateCloudTableClient();

myTable = tableClient.GetTableReference("myData");

TableOperation insertOperation = TableOperation.Insert(data);

myTable.ExecuteAsync(insertOperation);

代码在 Visual Studio 中本地运行良好,所有数据都正确写入位于 Azure 的表存储中。 但是,如果我将此代码 1:1 作为 Azure 函数部署到 Azure 中,该代码也运行良好,没有任何异常,日志显示,它贯穿每一行代码。

但没有数据写入表存储 - 相同的名称、相同的凭据、相同的代码。

与“本地 AzureFunc > Azure 表存储”相比,Azure 是否以某种方式阻止了此连接(Azure 中的 AzureFunc > Azure 表存储)?

【问题讨论】:

标签: azure azure-functions azure-table-storage


【解决方案1】:

Azure 是否阻止此连接(Azure 中的 AzureFunc > Azure 表 存储)以某种方式与“本地 AzureFunc > Azure Table 存储)?

不,阻止连接或类似的东西不是 azure。

您必须等待您正在使用 ExecuteAsync 执行的表操作,因为程序中的控件正在移动而该方法未完成。将最后一行代码更改为

await myTable.ExecuteAsync(insertOperation);

Because this call is not awaited, the current method continues to run before the call is completed 上看看如何。

【讨论】:

    【解决方案2】:

    问题出在行键上:

    我使用 DateTime.Now 作为行键(因为表存储不提供自动增量值)。 我的本地格式是“1.1.2019 18:19:20”,而服务器的格式是“1/1/2019 ...”

    而且行键字符串中似乎不允许出现“/”。

    现在,正确格式化 DateTime 字符串一切正常。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-03-29
      • 2014-07-17
      • 1970-01-01
      • 2018-09-07
      • 2013-02-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多