获取错误的请求错误在蔚蓝的表存储插入操作

在蔚蓝获取错误的请求错误在蔚蓝的表存储插入操作

Microsoft.WindowsAzure.Storage.StorageException: The remote server returned an error: (400) Bad Request. ---> System.Net.WebException: The remote server returned an error: (400) Bad Request. 

at System.Net.HttpWebRequest.GetResponse()

at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync[T]

(RESTCommand`1 cmd, IRetryPolicy policy, OperationContext operationContext) in c:\Program Files (x86)\Jenkins\workspace\release_dotnet_master\Lib\ClassLibraryCommon\Core\Executor\Executor.cs:line 677

--- End of inner exception stack trace ---

at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync[T]

(RESTCommand`1 cmd, IRetryPolicy policy, OperationContext operationContext) in c:\Program Files (x86)\Jenkins\workspace\release_dotnet_master\Lib\ClassLibraryCommon\Core\Executor\Executor.cs:line 604

at

Microsoft.WindowsAzure.Storage.Table.TableOperation.Execute(CloudTableClient client, CloudTable table, TableRequestOptions requestOptions, OperationContext operationContext) in c:\Program Files (x86)\Jenkins\workspace\release_dotnet_master\Lib\ClassLibraryCommon\Table\TableOperation.cs:line 44

at Microsoft.WindowsAzure.Storage.Table.CloudTable.Execute(TableOperation operation, TableRequestOptions requestOptions, OperationContext operationContext) in c:\Program Files (x86)\Jenkins\workspace\release_dotnet_master\Lib\ClassLibraryCommon\Table\CloudTable.cs:line 52

at pAvg15MinInstantInputWebJob.Avg15MinInstantInputJob.AverageCalculator(DateTime runningDate) in F:\Projects\LogiProjects\ProcessEye\Source\Kent.ProcessEye\pAvg15MinInstantInputWebJob\Avg15MinInstantInputJob.cs:line 246

Request Information

RequestID:855533de-0002-0066-2819-7f27ee000000

RequestDate:Wed, 27 Dec 2017 13:51:21 GMT

StatusMessage:Bad Request

ErrorCode:InvalidInput

ErrorMessage:Bad Request - Error in query syntax.

RequestId:855533de-0002-0066-2819-7f27ee000000

Time:2017-12-27T13:51:22.1788418Z

执行控制台webjob但在当地是成功的工作运行该应用程序时,我收到以下错误。

这里是我的代码

string connectionString1 = ConfigurationManager.ConnectionStrings["AzureWebJobsDashboard"].ConnectionString; 

CloudStorageAccount account1 = CloudStorageAccount.Parse(connectionString1);

CloudTableClient client1 = account1.CreateCloudTableClient();

CloudTable table2 = client1.GetTableReference(pAvg15MinInstantInput);

var row = new pAvg15MinInstantInputEntity();

row.PartitionKey = targetPartitionKey;

row.RowKey = rowDate.ToString();

row.avg = entity.average;

row.count = entity.count;

row.date = rowDate;

row.inputid = entity.inputid;

row.max = entity.max;

row.min = entity.min;

try

{

TableOperation insertOperation = TableOperation.InsertOrReplace(row);

table2.Execute(insertOperation);

}

catch (Exception ex)

{

Errorlogger(runningDate, "else ----->" + ex.ToString());

return false;

}

与实体类是如下

public class pAvg15MinInstantInputEntity : TableEntity 

{

public DateTime? date { get; set; }

public string inputid { get; set; }

public double? min { get; set; }

public double? max { get; set; }

public double? avg { get; set; }

public long? count { get; set; }

}

UPDATE

实体值如下

average - 244.1 

count - 3

date - 2017-12-27 10:15:26

inputid - 36-i1

max-244.1

min - 244.0

和实体类是如下

public class ResultModel 

{

public string inputid { get; set; }

//public long hour { get; set; }

//public long minute { get; set; }

public double max { get; set; }

public double min { get; set; }

public DateTime date { get; set; }

public double average { get; set; }

public long count { get; set; }

}

任何解决方案来解决这个问题?

回答:

由于Gaurav Mantri提到400错误通常是由无效值造成的。根据你提供的价值,似乎所有的价值都是正确的除了rowkey。我也可以重现它,如果我使用下面的代码,,因为它包含特征'/'。

RowKey = DateTime.Now.ToString(CultureInfo.InvariantCulture); 

在你的情况,你可以改变RowKey值固定值,如“测试”进行测试。我们也可以从Understanding the Table Service Data Model.

获取有关表enitity更多信息下列字符不在值允许为PartitionKey和RowKey属性:

正斜杠(/)字符

反斜杠()字符

数字符号(#)字符

问号(?)距离U字符

控制字符+ 0000至U + 001F,包括:

水平制表符(\ t)的字符

换行(\ n)的字符

回车( \距离U r)的字符

控制字符+ 007F到U + 009F


更新时间:

任何解决方案来解决这个问题?

你可以用下面的代码

row.RowKey = rowDate.ToString("yyyyMMddHHmmss") 

或有关如何格式化DATATIME

row.RowKey = rowDate.AddMilliseconds(1).Ticks.ToString() 

更多信息,请至另一SO thread

以上是 获取错误的请求错误在蔚蓝的表存储插入操作 的全部内容, 来源链接: utcz.com/qa/265538.html

回到顶部