Second Stanza

June 16, 2009

“Resource not found for the segment …” Azure Exception

Filed under: Azure Platform — Tags: — dfbaskin @ 12:48 pm

Using table storage within the Azure platform, a simple query was throwing an exception if the table entry was not found.


MyDataContext dataCtx = new MyDataContext( acctInfo );
var q = from entity in dataCtx.EmailAddresses
        where entity.PartitionKey == organizationID && entity.RowKey == address
        select entity;
EmailAddress emailAddr = q.FirstOrDefault();
return emailAddr;

I had assumed that an exception would not be thrown if there were no matching entries. The FirstOrDefault() method should have just returned null, right?

Well, not so. Here is a forum message gives a bit of a clue about how the query is actually processed and whether an exception is thrown or an empty data set is returned.

For right now, you’ll have to wrap the query in an exception block:


MyDataContext dataCtx = new MyDataContext( acctInfo );
var q = from entity in dataCtx.EmailAddresses
        where entity.PartitionKey == organizationID && entity.RowKey == address
        select entity;
EmailAddress emailAddr = null;
try
{
    emailAddr = q.FirstOrDefault();
}
catch( DataServiceQueryException ex )
{
}
return emailAddr;

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

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 )

Google photo

You are commenting using your Google 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 )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: