在我的表执行查询期间,我偶尔会遇到以下错误
System.InvalidOperationException: '已经有一个打开的 DataReader 与此命令关联,必须先关闭。'
private CloudTable table;
public AzureTableManager(string _CloudTableName)
{
if (string.IsNullOrEmpty(_CloudTableName))
{
throw new ArgumentNullException("Table", "Table Name can't be empty");
}
try
{
string ConnectionString = PrimariusOMS.Properties.Settings.Default.AzureTableStorage.ToString();
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConnectionString);
CloudTableClient tableClient = storageAccount.CreateCloudTableClient();
table = tableClient.GetTableReference(_CloudTableName);
table.CreateIfNotExists();
}
catch (StorageException StorageExceptionObj)
{
throw StorageExceptionObj;
}
catch (Exception ExceptionObj)
{
throw ExceptionObj;
}
}
public List<T> RetrieveEntity<T>(string TenantName, string Query = null) where T : TableEntity, new()
{
TableQuery<T> DataTableQuery = new TableQuery<T>();
if (!String.IsNullOrEmpty(Query))
{
Query += " and PartitionKey eq '" + TenantName + "'";
}
else { Query = "PartitionKey eq '" + TenantName + "'"; }
DataTableQuery = new TableQuery<T>().Where(Query);
IEnumerable<T> IDataList = table.ExecuteQuery(DataTableQuery);
List<T> DataList = new List<T>();
foreach (var singleData in IDataList)
DataList.Add(singleData);
return DataList;
}
此处返回错误:
IEnumerable<T> IDataList = table.ExecuteQuery(DataTableQuery);
这是我的示例调用:
List<AzureTableManager.DTTConfig> dtt = TableManagerObj.RetrieveEntity<AzureTableManager.DTTConfig>(tenantID, "RowKey eq 'Mass WhatIf'");
在 SQL 连接中,通过使用块或确保阅读器已关闭来克服此问题。我这里怎么处理?