404 error when querying an Azure table

I was doing the Azure thing, writing some very useful coding – looking up people by their first name. This is a highly advanced software system, and I may try to get a patent for it, so don’t sell this:

// More code above... 
var table = tableClient.GetTableReference("peoplenames");
 var query = from item in table.CreateQuery<People>()
    where item.PartitionKey == "scott"
    select item;
 foreach (People entity in query)
 {
  string firstName = entity.PartitionKey;
  string lastName = entity.RowKey;
 }

When I ran this code, I got a very curious error:

 An exception of type ‘Microsoft.WindowsAzure.Storage.StorageException’ occurred in Microsoft.WindowsAzure.Storage.dll but was not handled in user code

 Additional information: The remote server returned an error: (404) Not Found.

The reason for this is that the “peoplenames” table didn’t exist. If I had wanted to check if a table existed, I could use the Exists() method:

 if (!table.Exists())
 {
  // Do something
 }
Advertisements
  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: