【问题标题】:Task Scheduler Fails .Net 4.5 Console Application任务计划程序失败 .Net 4.5 控制台应用程序
【发布时间】:2015-12-02 22:13:45
【问题描述】:

我有一个用 C# 编写的 .Net 4.5 控制台应用程序,它使用 Entity Framework 6.1.3 调用 SQL 并生成 PDF。如果您运行可执行文件,应用程序运行良好,但通过任务计划程序运行时会失败。它只会在带有“仅在用户登录时运行”选项的任务计划程序上运行,我需要它在未登录时运行。

我在 Task Scheduler 中测试可执行文件的方法是模拟从 Entity Framework 调用的数据,并且应用程序工作得很好,所以有些事情告诉我 Task Scheduler 不喜欢我的 Entity Framework 调用。然而,我还有其他使用实体框架运行的计划任务。不知道问题是什么。以下是在 Windows 日志中看到的错误之一。

应用程序:CreatePDFFile.exe 框架版本:v4.0.30319 说明:进程因未处理的异常而终止。 异常信息:System.Data.SqlClient.SqlException 堆: 在 System.Data.Entity.Internal.RetryAction1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].PerformAction(System.__Canon) at System.Data.Entity.Internal.LazyInternalContext.InitializeDatabaseAction(System.Action1) 在 System.Data.Entity.Internal.LazyInternalContext.InitializeDatabase() 在 System.Data.Entity.Internal.LazyInternalContext.get_ObjectContext() 在 System.Data.Entity.Internal.InternalContext.ExecuteSqlQuery[[System.__Canon,mscorlib,版本=4.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089]](System.String,System.Nullable1<Boolean>, System.Object[]) at System.Data.Entity.Internal.InternalContext.ExecuteSqlQueryAsIEnumerator[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]](System.String, System.Nullable1,System.目的[]) 在 System.Data.Entity.Internal.InternalContext.ExecuteSqlQuery(System.Type,System.String,System.Nullable1<Boolean>, System.Object[]) at System.Data.Entity.Internal.InternalSqlNonSetQuery.GetEnumerator() at System.Data.Entity.Infrastructure.DbRawSqlQuery1[[System.__Canon,mscorlib,版本=4.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089] ].GetEnumerator() 在 System.Linq.Enumerable+WhereSelectEnumerableIterator2[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].MoveNext() at System.Collections.Generic.List1[[System.__Canon,mscorlib,版本=4.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089]]..ctor(System.Collections.Generic.IEnumerable1<System.__Canon>) at System.Linq.Enumerable.ToList[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]](System.Collections.Generic.IEnumerable1 ) 在 Repository.MyRepository.GetData(System.String, System.String, System.String, Int32)

【问题讨论】:

  • SqlExceptionInnerException 属性是什么?这会告诉你问题是什么。我猜它无法以系统用户身份连接到数据库。
  • 您是在连接字符串中使用 Windows 身份验证还是 SQL 服务器身份验证。可能是不允许系统用户连接到 SQL Server,而登录的用户可以(这就是为什么您可能会在 db 初始化时遇到错误)

标签: c# .net entity-framework scheduled-tasks


【解决方案1】:

我正在使用 SQL 身份验证。我添加了一个 try catch 错误,我得到了这个:

登录失败:登录来自不受信任的域,无法使用 使用 Windows 身份验证。

查看我的连接字符串后,我意识到我已将连接字符串从我的 PC 复制到服务器并替换了数据源但没有替换凭据......所以它已解决。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-01-13
    • 2012-05-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多