[英]Task Scheduler Fails .Net 4.5 Console Application
I have a .Net 4.5 Console Application written in C# that makes a call to SQL using Entity Framework 6.1.3 and generates a PDF. 我有一个用C#编写的.Net 4.5控制台应用程序,它使用Entity Framework 6.1.3调用SQL并生成PDF。 The application runs fine if you run the executable but it fails when ran through Task Scheduler.
如果您运行该可执行文件,则该应用程序可以正常运行,但是在通过Task Scheduler运行时,该应用程序将失败。 It will only run on Task Scheduler with option "Run only when user is logged in" I need it to run when not logged in.
它只能在Task Scheduler上运行,并带有“仅在用户登录时运行”选项。我需要它在未登录时运行。
What I did to test the executable in Task Scheduler was to mock the data gets called from Entity Framework and the application worked just fine so something tells me that Task Scheduler did not like my Entity Framework call. 我在Task Scheduler中测试可执行文件的工作是模拟从Entity Framework调用的数据,并且该应用程序运行良好,因此有些事情告诉我Task Scheduler不喜欢我的Entity Framework调用。 Yet I have other Schedule Tasks Running using Entity Framework.. Not sure what the problem is.
但是我还有其他使用实体框架运行的计划任务。。不确定是什么问题。 Below is one the error seen in Windows Log.
下面是Windows日志中看到的错误之一。
Application: CreatePDFFile.exe Framework Version: v4.0.30319 Description: The process was terminated due to an unhandled exception.
应用程序:CreatePDFFile.exe框架版本:v4.0.30319说明:该进程由于未处理的异常而终止。 Exception Info: System.Data.SqlClient.SqlException 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) at System.Data.Entity.Internal.LazyInternalContext.InitializeDatabase() at System.Data.Entity.Internal.LazyInternalContext.get_ObjectContext() at System.Data.Entity.Internal.InternalContext.ExecuteSqlQuery[[System.__Canon, mscorlib, Version=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.Nullable
1, System.Object[]) at System.Data.Entity.Internal.InternalContext.ExecuteSqlQuery(System.Type, System.String, Syste异常信息:System.Data.SqlClient.SqlException堆栈:位于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.LazyInternalContext.InitializeDatabase()位于System.Data.Entity.Internal.LazyInternalContext.get_ObjectContext() System.Data.Entity.Internal.InternalContext.ExecuteSqlQuery [[System .__ Canon,mscorlib,Version = 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.Nullable
1,System。 System.Data.Entity.Internal.InternalContext.ExecuteSqlQuery(System.Type,System.String,Syste处的Object []) m.Nullable1<Boolean>, System.Object[]) at System.Data.Entity.Internal.InternalSqlNonSetQuery.GetEnumerator() at System.Data.Entity.Infrastructure.DbRawSqlQuery
1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].GetEnumerator() at 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.List
1[[System.__Canon, mscorlib, Version=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.IEnumerable
1) at Repository.MyRepository.GetData(System.String, System.String, System.String, Int32)m.Nullable
1<Boolean>, System.Object[]) at System.Data.Entity.Internal.InternalSqlNonSetQuery.GetEnumerator() at System.Data.Entity.Infrastructure.DbRawSqlQuery
1 [[System .__ Canon,mscorlib,Version = 4.0 .0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089]]。GetEnumerator()at 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.List
1 [[System .__ Canon,mscorlib,Version = 4.0.0.0,Culture = neutral ,PublicKeyToken = b77a5c561934e089]] .. ctor(1<System.__Canon>) at System.Linq.Enumerable.ToList[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]](System.Collections.Generic.IEnumerable
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.IEnumerable
位于Repository.MyRepository.GetData(System.String,System.String,System.String,Int32)的1<System.__Canon>) at System.Linq.Enumerable.ToList[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]](System.Collections.Generic.IEnumerable
1)
I am using SQL Authentication. 我正在使用SQL身份验证。 I added a try catch error and I get this:
我添加了一个try catch错误,我得到了:
Login failed: The login is from an untrusted domain and cannot be used with Windows Authentication.
登录失败:登录来自不受信任的域,不能与Windows身份验证一起使用。
After looking at my connection string, I realized that I had copied the connectionstring from my PC to the server and replaced the data source but not the credentials....So its resolved. 查看连接字符串后,我意识到我已将连接字符串从PC复制到服务器并替换了数据源,但没有替换凭据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.