Jack Scott
Jack Scott

Reputation: 442

Exception when querying SQL Azure database from Azure Worker Role

I have an Azure worker role which is supposed to query an Azure-based SQL database for items that need updating, performs a calculation and saves the result. Pretty simple stuff, and I've had no trouble getting it to work in the Azure Compute Emulator on my local machine, both against a LocalDb and against the Azure-based production database.

When running in the cloud however I get the following exception, and I have no idea what is causing it:

Application: WaWorkerHost.exe

Framework Version: v4.0.30319

Description: The process was terminated due to an unhandled exception.

Exception Info: System.Data.DataException

Stack:

   at System.Data.Entity.Internal.RetryAction`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].PerformAction(System.__Canon)
   at System.Data.Entity.Internal.LazyInternalContext.InitializeDatabaseAction(System.Action`1<System.Data.Entity.Internal.InternalContext>)
   at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(System.Type)
   at System.Data.Entity.Internal.Linq.InternalSet`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].Initialize()
   at System.Data.Entity.Internal.Linq.InternalSet`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].get_InternalContext()
   at System.Data.Entity.Infrastructure.DbQuery`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].System.Linq.IQueryable.get_Provider()
   at System.Linq.Queryable.Where[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]](System.Linq.IQueryable`1<System.__Canon>, System.Linq.Expressions.Expression`1<System.Func`2<System.__Canon,Boolean>>)
   at Workzerk.Worker.Events.EventsWorkerRole.Run()
   at Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.StartRoleInternal()
   at Microsoft.WindowsAzure.ServiceRuntime.Implementation.Loader.RoleRuntimeBridge.<StartRole>b__2()
   at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
   at System.Threading.ThreadHelper.ThreadStart()

This piece of code runs fine (in the OnStart method):

string connectionString = RoleEnvironment.GetConfigurationSettingValue("SampleDbConnectionString");
Trace.TraceInformation("The connection string for the database is: " + connectionString);
_db = new SampleDbContext(connectionString);

The correct connection string gets output to the logs.

Unfortunately the following code throws the exception (this code in the Run method):

Event[] events = _db.Events.Where(x => x.NextOccurence != null).ToArray();

Event is one of our domain objects.

Does anybody know what is causing this exception, or how I could best go about finding out?

Upvotes: 0

Views: 347

Answers (1)

Vadim K.
Vadim K.

Reputation: 1101

Exception description you are getting is unclear. Try to wrap your piece of code in try/catch block and log the exception details into Trace. Make sure you also log InnerException(s) details.

Upvotes: 1

Related Questions