Pergunta

I have built an appender that writes Log4Net logs to a SimpleDB table/domain called LogTable. I am now trying to write a windows service which will delete old records from this table. The AmazonSimpleDB client is definitely being created and the query when run manually does return records. However when the code is executed through a unit test no results are returned. The table and column name case sensitivity are correct.

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

Would really appreciate some help on this one.

Foi útil?

Solução

Only records that satisfy the expression will be returned so please make sure your query is correct. what does a simple select query return? Try this and check -

select * from LogTable  

If you are not getting any hits then please specify the region end point.

and if it returns then please make sure the condition you have specified is getting matched.

Edited :

Please try to run this code and specify region end point using this link to which your domain belongs.

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;
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top