gpt4 book ai didi

c# - Azure 存储表返回异常 400 错误请求

转载 作者:太空狗 更新时间:2023-10-30 00:47:46 24 4
gpt4 key购买 nike

我正在尝试创建 azure 存储表并使用 C# 将记录插入其中。我已成功创建该表,但在向其中插入记录时出现 400 Bad Request 存储异常。

检查调试器后:

StorageException.RequestInformation.ExtendedErrorInformation.ErrorMessage

显示 OutOfRangeInput 错误

"One of the request inputs is out of range.\nRequestId:862fdbae-6002-000c-1e7c-ef9373000000\nTime:2019-04-10T09:06:05.9840359Z"

我接受了这个帖子的帮助Azure table storage returns 400 Bad Request

  • 尝试将 null 传递到我的实体模型变量中以查看是否有任何记录超出范围
  • 尝试通过 RowKey 中的“测试”
  • 尝试在 PartitionKey 中传递“1”/“test”
  • 尝试在 RowKey 中传递 Guid.NewGuid().ToString() 或 ToAzureKeyString(Guid.NewGuid().ToString())
  • 尝试在时间戳中传递 DateTimeOffset.Now

仍然给我同样的错误。这是我的代码:

public void GetGPSFileData(Config objConfig, TraceWriter log)
{
try
{
BindData objData = new BindData();
string date = DateTime.Now.Date.ToString("ddMMyyyy");
string storageTable = "TABLE" + date + objData.REPCODE;
TableStorage tableStorage = new TableStorage(objData);
CreateTableStorage(objConfig, storageTable, tableStorage, log);
}
catch (StorageException ex)
{
log.Info($"Storage Exception while reading GPS File Data from Azure Storage: " + ex.RequestInformation.ExtendedErrorInformation.ErrorMessage + DateTime.Now);
throw ex;
}
catch (Exception ex)
{
log.Info($"Error while reading GPS File Data from Azure Storage: " + ex.Message + DateTime.Now);
throw ex;
}
}

表存储.cs

public class TableStorage: TableEntity
{
public string CLIENTID { get; set; }
public string REPCODE { get; set; }
public int ENTRYNO { get; set; }
public string DEVICEID { get; set; }
public double LAT { get; set; }
public double LNG { get; set; }
public DateTime DATE_TIME { get; set; }

public string PCODE { get; set; }
public string PNAME { get; set; }
public DateTime TXNDATE { get; set; }

public TableStorage(BindData objData)
{
PartitionKey = objData.CLIENTID;
RowKey = ToAzureKeyString(Guid.NewGuid().ToString());
Timestamp = DateTimeOffset.Now;

CLIENTID = objData.CLIENTID;
REPCODE = objData.REPCODE;
ENTRYNO = objData.ENTRYNO;
DEVICEID = objData.DEVICEID;
LAT = objData.LAT;
LNG = objData.LNG;
DATE_TIME = objData.DATE_TIME;
PCODE = objData.PCODE;
PNAME = objData.PNAME;
TXNDATE = objData.TXNDATE;
}

public string ToAzureKeyString(string str)
{
var sb = new StringBuilder();
foreach (var c in str
.Where(c => c != '/'
&& c != '\\'
&& c != '#'
&& c != '/'
&& c != '?'
&& !char.IsControl(c)))
sb.Append(c);
return sb.ToString();
}
}

创建并插入存储表代码:

public void CreateTableStorage(Config objConfig, string tableName, TableStorage tableStorage, TraceWriter log)
{
try
{
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(objConfig.TABLE_STORAGE_CONN_STRING);
CloudTableClient tableClient = storageAccount.CreateCloudTableClient();
CloudTable table = tableClient.GetTableReference(tableName);
table.CreateIfNotExists();

TableOperation insert = TableOperation.Insert(tableStorage);
table.Execute(insert);
}
catch(StorageException ex)
{
log.Info($"Storage Exception while inserting record into Table Storage: " + ex.RequestInformation.ExtendedErrorInformation.ErrorMessage + DateTime.Now);
throw ex;
}
catch(Exception ex)
{
log.Info($"Error while inserting record into Table Storage: " + ex.Message + DateTime.Now);
throw ex;
}
}

TableStorage 类的对象包含: tableStorage obj

可能是什么问题?我是全新的 azure 储物 table 。请帮忙。提前致谢。

最佳答案

问题是由 TXNDATE 属性的值引起的。如果您查看共享的图片,您发送的值是 1/1/01(即 DateTime.MinValue),而允许的最小值是 1601 年 1 月 1 日

一旦您为 TXNDATE 传递了正确的值,您就不会看到此错误。

关于c# - Azure 存储表返回异常 400 错误请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55609140/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com