繁体   English   中英

从Azure Worker角色查询SQL Azure数据库时发生异常

[英]Exception when querying SQL Azure database from Azure Worker Role

我有一个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();

事件是我们的领域对象之一。

有人知道导致此异常的原因是什么,或者我最好如何找到答案?

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM