1

我已经构建了一个附加程序,它将 Log4Net 日志写入一个名为 LogTable 的 SimpleDB 表/域。我现在正在尝试编写一个 Windows 服务,该服务将从该表中删除旧记录。肯定会创建 AmazonSimpleDB 客户端,手动运行时的查询确实会返回记录。但是,当通过单元测试执行代码时,不会返回任何结果。表名和列名区分大小写是正确的。

using (AmazonSimpleDB simpleDbClient = AWSClientFactory.CreateAmazonSimpleDBClient(accessKey, secretKey))
                {
                    String selectExpression = String.Format("select * from LogTable where Timestamp < '{0:o}'", purgeDate);
                    SelectRequest selectRequestAction = new SelectRequest().WithSelectExpression(selectExpression);
                    SelectResponse selectResponse = simpleDbClient.Select(selectRequestAction);

                    if (selectResponse.IsSetSelectResult())
                    {
                        BatchDeleteAttributesRequest deleteRequest = new BatchDeleteAttributesRequest().WithDomainName("LogTable");
                        deleteRequest.Item = new List<DeleteableItem>();

                        SelectResult selectResult = selectResponse.SelectResult;
                        foreach (Item item in selectResult.Item)
                        {
                            deleteRequest.Item.Add(new DeleteableItem { ItemName = item.Name });
                        }

                        if (deleteRequest.Item.Count > 0)
                        {
                            simpleDbClient.BatchDeleteAttributes(deleteRequest);
                        }

                        logger.InfoFormat("Success - {0} log records deleted from LogTable", deleteRequest.Item.Count);
                    }
}

非常感谢对此提供一些帮助。

4

1 回答 1

0

只有满足表达式的记录才会被返回,所以请确保您的查询是正确的。一个简单的选择查询返回什么?试试这个并检查 -

select * from LogTable  

如果您没有得到任何点击,请指定区域终点。

如果它返回,请确保您指定的条件得到匹配。

编辑:

请尝试运行此代码并使用您的域所属的此链接指定区域端点。

AmazonSimpleDBConfig theConfig = new AmazonSimpleDBConfig();
theConfig.ServiceURL = myEndpoint;  //where myEndPoint is the region endpoint you are interested in
AmazonSimpleDBClient simpleDbClient= new AmazonSimpleDBClient(myKey, mySecretKey, theConfig);
String selectExpression = "select * from LogTable";
SelectRequest selectRequestAction = new SelectRequest();
selectRequestAction.SelectExpression = selectExpression;
selectRequestAction.NextToken = null;
SelectResponse selectResponse = simpleDbClient.Select(selectRequestAction);
SelectResult selectResult = selectResponse.SelectResult;
List<Item> itemList = selectResult.Item;
于 2013-01-22T06:56:09.297 回答