我们使用DataContext从数据库中选择一行,更新几列(布尔值和字节列),然后调用SubmitChanges().当我们提交更改时,我们会收到包含以下堆栈跟踪的DivideByZeroException:
System.DivideByZeroException: Attempted to divide by zero.
at System.Data.sqlServerCe.NativeMethodsHelper.CompileQueryPlan(IntPtr
pQpCommand,String pwszCommandText,ResultSetOptions options,IntPtr[]
pParamNames,IntPtr prgBinding,Int32 cDbBinding,IntPtr& pQpPlan,
IntPtr pError)
at System.Data.sqlServerCe.NativeMethods.CompileQueryPlan(IntPtr pQpCommand,
IntPtr pError)
at System.Data.sqlServerCe.sqlCeCommand.CompileQueryPlan()
at System.Data.sqlServerCe.sqlCeCommand.ExecuteCommand(CommandBehavior
behavior,String method,ResultSetOptions options)
at System.Data.sqlServerCe.sqlCeCommand.ExecuteNonQuery()
at System.Data.Linq.sqlClient.sqlProvider.Execute(Expression query,QueryInfo queryInfo,IObjectReaderFactory factory,Object[]
parentArgs,Object[] userArgs,ICompiledSubQuery[] subQueries,Object
lastResult)
at System.Data.Linq.sqlClient.sqlProvider.ExecuteAll(Expression query,QueryInfo[] queryInfos,Object[]
userArguments,ICompiledSubQuery[] subQueries)
at System.Data.Linq.sqlClient.sqlProvider.System.Data.Linq.Provider.IProvider.Execute(Expression
query)
at System.Data.Linq.ChangeDirector.StandardChangeDirector.DynamicUpdate(TrackedObject
item)
at System.Data.Linq.ChangeDirector.StandardChangeDirector.Update(TrackedObject
item)
at System.Data.Linq.ChangeProcessor.SubmitChanges(ConflictMode failureMode)
at System.Data.Linq.DataContext.SubmitChanges(ConflictMode failureMode)
at System.Data.Linq.DataContext.SubmitChanges()
编辑:
在分析时,问题似乎是在delete语句上生成的,类似于:
DELETE FROM [WorkItemUid]
WHERE ([Oid] = 24151 /* @p0 /)
AND ([WorkItemOid] = 745 / @p1 /)
AND ([SeriesInstanceUid] = ‘1.3.12.2.1107.5.1.4.54023.30000004101914490887500000063’ / @p2 /)
AND ([SopInstanceUid] = ‘1.3.12.2.1107.5.1.4.54023.30000004101913521221800001089’ / @p3 /)
AND ([Complete] = 1)
AND ([FailureCount] = 0 / @p4 */)
AND ([File] IS NULL)
AND (NOT ([Failed] = 1))
错误发生在我试图单独删除~1500外键记录的声明中.当我更改代码以单独删除行时,我将其缩小到大约45行无法删除的行.然后我使用sql Compact查询分析器尝试在行本身上执行删除,并且它也在那里失败,并且除以零异常.
因此,它似乎不是Linq-to-sql错误,而是sql Server Compact CE 4.0本身删除这些行的东西.我试图删除并开始使用干净的数据库,并复制填充然后从数据库中删除,然后再次出现问题.当有>这可能是个问题. 1500个外键记录删除时发生的事情.
一堆谷歌搜索大多是空的,但我确实在this参考时找到了对sql Server CE 3.5的DivideByZeroException的引用.我已经确认我正在使用sql Server CE 4.0程序集,所以这似乎不是问题.有关上述错误是否仍适用于sql Server CE 4.0的任何想法?经过进一步审查后,它出现了同样的问题.