2017-12-27 307 views
0

在蔚藍獲取錯誤的請求錯誤在蔚藍的表存儲插入操作

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; } 
} 

任何解決方案來解決這個問題?

+0

「錯誤格式化rowDate查詢語法「。您的輸入在本地和服務器之間必須不同。 – Crowcoder

+0

如果我在本地和服務器上使用相同資源,會發生什麼情況? –

+0

我建議你調試它。你在使用VS 2017嗎?如果是這樣得到最新的更新和[看到這個](https://www.visualstudio.com/vs/debug-in-azure/) – Crowcoder

回答

1

由於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

+0

沒有工作.. –

+0

您是否使用固定值「test」的RowKey進行測試? –

+0

是的。然後它的工作.. –

相關問題