列出存储帐户中的所有azure表

时间:2014-03-25 01:17:56

标签: azure azure-table-storage

我正在尝试列出所有azure表,然后迭代它们以删除每个表。首先,我获取所有云表的列表,然后尝试迭代所有云表。但它让我对它有所了解。

代码如下

CloudStorageAccount account = CloudStorageAccount.Parse(connectionString);
CloudTableClient tableClient;
IEnumerable<CloudTable> tables = tableClient.ListTables();
foreach (CloudTable table in tables)
                table.DeleteIfExists();

for for循环是中断,不允许迭代。以下是例外情况。

  

at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync [T](StorageCommandBase 1 cmd, IRetryPolicy policy, OperationContext operationContext) at Microsoft.WindowsAzure.Storage.Table.TableQuery 1.ExecuteQuerySegmented(TableContinuationToken令牌,CloudTableClient客户端,String tableName,TableRequestOptions requestOptions,OperationContext operationContext)       在Microsoft.WindowsAzure.Storage.Table.TableQuery 1.<>c__DisplayClass7.<Execute>b__6(IContinuationToken continuationToken) at Microsoft.WindowsAzure.Storage.Core.Util.CommonUtility.<LazyEnumerable>d__0 1.MoveNext()       在System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()       在C:\ Users \ vargup \ Documents \ Visual Studio 2013 \ Projects \ CleanStorageAccount \ CleanStorageAccount \ Program.cs中的CleanStorageAccount.Program.Main(String [] args):第34行       在System.AppDomain._nExecuteAssembly(RuntimeAssembly程序集,String [] args)       在System.AppDomain.ExecuteAssembly(String assemblyFile,Evidence assemblySecurity,String [] args)       在Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()       在System.Threading.ThreadHelper.ThreadStart_Context(对象状态)       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext,ContextCallback callback,Object state,Boolean preserveSyncCtx)       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback callback,Object state,Boolean preserveSyncCtx)       在System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback回调,对象状态)       在System.Threading.ThreadHelper.ThreadStart()

2 个答案:

答案 0 :(得分:2)

我将Microsoft.WindowsAzure.Storage.dll引用更新为2.1到3.1版本,相同的代码适用于我。

答案 1 :(得分:1)

这很好用:

    CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
        CloudConfigurationManager.GetSetting("StorageConnectionString"));
    CloudTableClient tableClient = storageAccount.CreateCloudTableClient();

    var table = tableClient.ListTables();

    foreach (CloudTable t in table)
    {
        insertEntity(t.Name, boxNewPage.Text, '', '');
    }