【问题标题】:Exception when querying SQL Azure database from Azure Worker Role从 Azure Worker Role 查询 SQL Azure 数据库时出现异常
【发布时间】:2014-04-15 03:11:08
【问题描述】:

我有一个 Azure 工作者角色,它应该查询基于 Azure 的 SQL 数据库以查找需要更新的项目、执行计算并保存结果。非常简单的东西,我可以毫不费力地让它在本地机器上的 Azure Compute Emulator 中运行,无论是针对 LocalDb 还是针对基于 Azure 的生产数据库。

但是在云中运行时出现以下异常,我不知道是什么原因造成的:

申请: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();

Event 是我们的领域对象之一。

有谁知道是什么导致了这个异常,或者我怎样才能最好地找出答案?

【问题讨论】:

    标签: c# linq azure azure-sql-database azure-worker-roles


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2016-08-14
      • 2015-03-17
      • 2013-04-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-24
      • 2014-05-22
      • 2013-12-03
      相关资源
      最近更新 更多