2014-01-20 29 views
0
刪除數據

我試圖使用所提供的解決方案從我WADLogsTable刪除數據here問題而來自WADLogsTable

我已經修改了它一下叫developmentstorage但代碼拋出與遠程服務器異常返回了一個錯誤: (400)錯誤的請求。說「其中一個請求輸入超出範圍」。執行這行代碼,如果(items.Count()== 0)

以下後是我的代碼

public static async void TruncateDiagnostics() 
    { 
     Uri test = new Uri("http://127.0.0.1:10002/Tables/"); 
     while (true) 
     { 
      try 
      { 
       // Retrieve storage account from connection-string 
       CloudStorageAccount storageAccount = CloudStorageAccount.DevelopmentStorageAccount; 
       Microsoft.WindowsAzure.Storage.Table.CloudTableClient tableClientObj = new Microsoft.WindowsAzure.Storage.Table.CloudTableClient(test); 
       CloudTable cloudTable = tableClientObj.GetTableReference("wadlogstable"); 

       // keep a hours worth of logs 
       DateTime keepThreshold = DateTime.UtcNow.AddHours(-1); 

       // do this until we run out of items 
       while (true) 
       { 
        TableQuery query = new TableQuery(); 
        query.FilterString = string.Format("PartitionKey < '0{0}'", keepThreshold.Ticks); 
        var items = cloudTable.ExecuteQuery(query); 

        if (items.Count() == 0) 
         break; 

        Dictionary<string, TableBatchOperation> batches = new Dictionary<string, TableBatchOperation>(); 
        foreach (var entity in items) 
        { 
         TableOperation tableOperation = TableOperation.Delete(entity); 

         // need a new batch? 
         if (!batches.ContainsKey(entity.PartitionKey)) 
          batches.Add(entity.PartitionKey, new TableBatchOperation()); 

         // can have only 100 per batch 
         if (batches[entity.PartitionKey].Count < 100) 
          batches[entity.PartitionKey].Add(tableOperation); 
        } 

        // execute! 
        foreach (var batch in batches.Values) 
         await cloudTable.ExecuteBatchAsync(batch); 

        Trace.TraceInformation("WADLogsTable truncated: " + query.FilterString); 
       } 
      } 
      catch (Exception ex) 
      { 
       Trace.TraceError("Truncate WADLogsTable exception {0}", ex.Message); 
      } 

      // run this once per day 
      await Task.Delay(TimeSpan.FromDays(1)); 
     } 
    } 

我堅持這個問題有一段時間了。任何幫助將不勝感激。 在此先感謝。

回答

0

嘗試:

query.FilterString = string.Format("PartitionKey gt '0{0}'", keepThreshold.Ticks); 
query.FilterString = string.Format("PartitionKey lt '0{0}'", keepThreshold.Ticks); 

查詢不是直到你的foreach循環執行