首页 文章

从Azure辅助角色查询SQL Azure数据库时出现异常

提问于
浏览
0

我有一个Azure辅助角色,它应该在基于Azure的SQL数据库中查询需要更新的项目,执行计算并保存结果 . 非常简单的东西,我在本地计算机上的Azure计算模拟器中工作时都没有遇到任何问题,无论是针对 LocalDb 还是基于Azure的 生产环境 数据库 .

但是当在 Cloud 中运行时,我得到以下异常,我不知道是什么导致它:

申请: WaWorkerHost.exe

框架版本: v4.0.30319

说明: The process was terminated due to an unhandled exception.

例外信息: System.Data.DataException

堆:

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()

这段代码运行正常(在OnStart方法中):

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

正确的连接字符串将输出到日志 .

不幸的是,以下代码抛出异常(此代码在Run方法中):

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

事件是我们的域对象之一 .

有人知道造成这种异常的原因,或者我最好怎么找出来?

1 回答

  • 1

    你得到的例外描述尚不清楚 . 尝试将您的代码包装在try / catch块中,并将异常详细信息记录到Trace中 . 确保您还记录InnerException(s)详细信息 .

相关问题