Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 执行SqlBulkCopy时未处理的异常_C#_Entity Framework - Fatal编程技术网

C# 执行SqlBulkCopy时未处理的异常

C# 执行SqlBulkCopy时未处理的异常,c#,entity-framework,C#,Entity Framework,我已在任务计划程序中配置了控制台应用程序 控制台应用程序通过从csv文件中读取数据,使用SqlBulkCopy将数据插入sql表 问题是作业随机抛出了我无法使用try-catch捕获的异常 但是,它会以以下方式登录到事件查看器: Application: ApplicationName.exe Framework Version: v4.0.30319 Description: The process was terminated due to an unhandled exception. E

我已在任务计划程序中配置了控制台应用程序

控制台应用程序通过从csv文件中读取数据,使用SqlBulkCopy将数据插入sql表

问题是作业随机抛出了我无法使用try-catch捕获的异常

但是,它会以以下方式登录到事件查看器:

Application: ApplicationName.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info:  System.Data.Entity.Infrastructure.DbUpdateException
Stack:
   at System.Data.Entity.Internal.InternalContext.SaveChanges()
   at System.Data.Entity.Internal.LazyInternalContext.SaveChanges()
   at System.Data.Entity.DbContext.SaveChanges()
   at SDO.Repository.Repository`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].SaveChanges()
   at SDO.Business.SolutionDB.SolverProcess.ProcessConsoleOutput(System.Object, System.Diagnostics.DataReceivedEventArgs)
   at System.Diagnostics.Process.OutputReadNotifyUser(System.String)
   at System.Diagnostics.AsyncStreamReader.FlushMessageQueue()
   at System.Diagnostics.AsyncStreamReader.ReadBuffer(System.IAsyncResult)
   at System.IO.Stream+ReadWriteTask.InvokeAsyncCallback(System.Object)
   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.IO.Stream+ReadWriteTask.System.Threading.Tasks.ITaskCompletionAction.Invoke(System.Threading.Tasks.Task)
   at System.Threading.Tasks.Task.FinishContinuations()
   at System.Threading.Tasks.Task.FinishStageThree()
   at System.Threading.Tasks.Task.FinishStageTwo()
   at System.Threading.Tasks.Task.Finish(Boolean)
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(System.Threading.Tasks.Task ByRef)
   at System.Threading.Tasks.Task.ExecuteEntry(Boolean)
   at System.Threading.Tasks.Task.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
   at System.Threading.ThreadPoolWorkQueue.Dispatch()
   at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()
任务计划程序作业在这一点上卡住了。 仅供参考,我使用的是EntityFramework6数据库优先方法。
当我们在一个表中插入超过30k的数据时,我使用了SqlBulkCopy方法,它的性能非常好。但是,这是我们面临的唯一问题。

您检查过文件数据了吗?通常问题源于csv数据。同一个文件有时上传得很好。这是随机行为。同一文件可能具有不同的数据。你调试文件了吗?实际上我们有生成文件的场景。行数一切都很完美。我调试了它,但是调试成功了。但是,当通过作业调度器执行相同的操作时,它会失败,并且只在事件查看器中记录上述异常。另外,为了澄清这一点,它大部分时间也是通过作业调度器工作的。