4
votes

I am trying to list all azure tables and then iterate over them to delete each table. Here first I get list of all cloud tables and then trying to iterate over all cloud tables. But it gives me exception on lopping over it.

Code is as follows

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

At for loop is breaks and does not allows to iterate. Below is the exception details.

at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync[T](StorageCommandBase1 cmd, IRetryPolicy policy, OperationContext operationContext) at Microsoft.WindowsAzure.Storage.Table.TableQuery1.ExecuteQuerySegmented(TableContinuationToken token, CloudTableClient client, String tableName, TableRequestOptions requestOptions, OperationContext operationContext) at Microsoft.WindowsAzure.Storage.Table.TableQuery1.<>c__DisplayClass7.<Execute>b__6(IContinuationToken continuationToken) at Microsoft.WindowsAzure.Storage.Core.Util.CommonUtility.<LazyEnumerable>d__01.MoveNext() at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext() at CleanStorageAccount.Program.Main(String[] args) in c:\Users\vargup\Documents\Visual Studio 2013\Projects\CleanStorageAccount\CleanStorageAccount\Program.cs:line 34 at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) 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) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart()

2
Where/How do you define tableClient?crthompson
That doesnt look like a complete stack trace either.crthompson
Added table client declaration. Yes stacktrace is complete. I got to know the solution, I updated my Microsoft.WindowsAzure.Storage.dll from 2.1 to 3.1 and it started working.Varun Gupta
Glad you got it working. In your error there is no actual error message, thats why I thought you are missing something.crthompson

2 Answers

2
votes

I updated Microsoft.WindowsAzure.Storage.dll reference from 2.1 to 3.1 version and same code worked for me.

1
votes

This works fine:

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