NHibernate 不一致的 SQLDateTime 溢出
我们有一个非常奇怪的错误,有时当我们想要从 WCF 服务中保存某些内容时,我们会收到此错误。我们正在保存的对象不包含无效的日期时间,我们在保存之前都会检查它们。当我们看到此错误时,数据库有时会挂起,并且 WCF 处于错误状态。当我重新启动数据库和托管 WCF 的 IIS Web 应用程序并尝试再次保存时。有用.. 我们一无所知,因此如果有人有任何建议,请分享
以下是错误:
2010-03-05 10:21:34,311 [5] 错误 ProjectX.Business.TTExceptionLogger - ReceiveResultsForMobile() 中的某处出现异常:{0} Castle.Services.Transaction.CommitResourceException:无法提交事务,一个(或多个)资源失败 ---> System.Data.SqlTypes.SqlTypeException:SqlDateTime 溢出。必须介于 1/1/1753 12:00:00 AM 和 12/31/9999 11:59:59 PM 之间。 在 System.Data.SqlTypes.SqlDateTime.FromTimeSpan(TimeSpan 值) 在 System.Data.SqlTypes.SqlDateTime.FromDateTime(日期时间值) 在 System.Data.SqlClient.MetaType.FromDateTime(DateTime dateTime,字节 cb) 在System.Data.SqlClient.TdsParser.WriteValue(对象值,MetaType类型,字节比例,Int32实际长度,Int32编码ByteSize,Int32偏移量,TdsParserStateObject stateObj) 在 System.Data.SqlClient.TdsParser.TdsExecuteRPC(_SqlRPC[] rpcArray,Int32 超时,布尔 inSchema,SqlNotificationRequest notificationRequest,TdsParserStateObject stateObj,布尔 isCommandProc) 在 System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior、RunBehavior runBehavior、布尔 returnStream、布尔异步) 在 System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior、RunBehavior runBehavior、布尔 returnStream、字符串方法、DbAsyncResult 结果) 在 System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult 结果,字符串方法名称,布尔值 sendToPipe) 在 System.Data.SqlClient.SqlCommand.ExecuteNonQuery() 在NHibernate.AdoNet.AbstractBatcher.ExecuteNonQuery(IDbCommand cmd) 在 NHibernate.AdoNet.NonBatchingBatcher.AddToBatch(IExpectation 期望) 在NHibernate.Persister.Entity.AbstractEntityPersister.Update(对象id,对象[]字段,对象[] oldFields,对象rowId,布尔[] includeProperty,Int32 j,对象oldVersion,对象obj,SqlCommandInfo sql,ISessionImplementor会话) 在NHibernate.Persister.Entity.AbstractEntityPersister.UpdateOrInsert(对象id,对象[]字段,对象[] oldFields,对象rowId,布尔[] includeProperty,Int32 j,对象oldVersion,对象obj,SqlCommandInfo sql,ISessionImplementor会话) 在NHibernate.Persister.Entity.AbstractEntityPersister.Update(对象id,对象[]字段,Int32[] dirtyFields,布尔值hasDirtyCollection,对象[] oldFields,对象oldVersion,对象obj,对象rowId,ISessionImplementor会话) 在 NHibernate.Action.EntityUpdateAction.Execute() 在NHibernate.Engine.ActionQueue.Execute(IExecutable可执行文件) 在NHibernate.Engine.ActionQueue.ExecuteActions(IList列表) 在 NHibernate.Engine.ActionQueue.ExecuteActions() 在 NHibernate.Event.Default.AbstractFlushingEventListener.PerformExecutions(IEventSource 会话) 在NHibernate.Event.Default.DefaultFlushEventListener.OnFlush(FlushEvent事件) 在 NHibernate.Impl.SessionImpl.Flush() 在 NHibernate.Transaction.AdoTransaction.Commit() 在 Rhino.Commons.NHibernateTransactionAdapter.Commit() 在Rhino.Commons.Facilities.RhinoTransactionResourceAdapter.Commit() 在 Castle.Services.Transaction.AbstractTransaction.Commit() --- 内部异常堆栈跟踪结束 --- 在 Castle.Services.Transaction.AbstractTransaction.Commit() 在 Castle.Services.Transaction.StandardTransaction.Commit() 在Castle.Facilities.AutomaticTransactionManagement.TransactionInterceptor.Intercept(IInitation调用) 在 Castle.DynamicProxy.AbstractInspiration.Proceed() 在 IReceiveServiceProxy61c28a82c9a24e96957e32292b924889.Save(接收实例) 在 D:\Project Docs\Clients\ClientX 09.08\Projects\ProjectX\ProjectX.WcfInterfaceService\MobileServices.svc 中的 WcfInterfaceService.MobileServices.SaveReceiveLines(IEnumerable1 receiveLines、字符串warehouseCode、字符串用户名、字符串deviceNumber、布尔值removeOldReceiveLines)。 CS:第 567 行 在 D:\Project Docs\Clients\ClientX 09.08\Projects\ProjectX\ProjectX.WcfInterfaceService\MobileServices.svc.cs 中的 WcfInterfaceService.MobileServices.ProcessReceiveResults(List
1 receiveLines、字符串warehouseCode、字符串用户名、字符串deviceNumber): 770线 在 D:\Project Docs\Clients\ClientX 09.08\Projects\ProjectX\ProjectX.WcfInterfaceService\MobileServices.svc.cs 中的 WcfInterfaceService.MobileServices.ProcessResultsFromMobile(字符串 receiveResult、字符串仓库Code、字符串用户名、字符串 deviceNumber):第 668 行
We have a very strange error that sometimes we get this error when we want to save something from our WCF service. The object that we are saving contains NO invalid datetimes, we all check them before we save. When we see this error the database hangs sometimes and the WCF is in a faulty state. When I restart the DB and the IIS web app where the WCF is hosted and try to save again. It works..
We are clueless so if any one has some advice, please share
Following is the error:
2010-03-05 10:21:34,311 [5] ERROR ProjectX.Business.TTExceptionLogger - Exception somewhere in ReceiveResultsForMobile(): {0}
Castle.Services.Transaction.CommitResourceException: Could not commit transaction, one (or more) of the resources failed ---> System.Data.SqlTypes.SqlTypeException: SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.
at System.Data.SqlTypes.SqlDateTime.FromTimeSpan(TimeSpan value)
at System.Data.SqlTypes.SqlDateTime.FromDateTime(DateTime value)
at System.Data.SqlClient.MetaType.FromDateTime(DateTime dateTime, Byte cb)
at System.Data.SqlClient.TdsParser.WriteValue(Object value, MetaType type, Byte scale, Int32 actualLength, Int32 encodingByteSize, Int32 offset, TdsParserStateObject stateObj)
at System.Data.SqlClient.TdsParser.TdsExecuteRPC(_SqlRPC[] rpcArray, Int32 timeout, Boolean inSchema, SqlNotificationRequest notificationRequest, TdsParserStateObject stateObj, Boolean isCommandProc)
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe)
at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
at NHibernate.AdoNet.AbstractBatcher.ExecuteNonQuery(IDbCommand cmd)
at NHibernate.AdoNet.NonBatchingBatcher.AddToBatch(IExpectation expectation)
at NHibernate.Persister.Entity.AbstractEntityPersister.Update(Object id, Object[] fields, Object[] oldFields, Object rowId, Boolean[] includeProperty, Int32 j, Object oldVersion, Object obj, SqlCommandInfo sql, ISessionImplementor session)
at NHibernate.Persister.Entity.AbstractEntityPersister.UpdateOrInsert(Object id, Object[] fields, Object[] oldFields, Object rowId, Boolean[] includeProperty, Int32 j, Object oldVersion, Object obj, SqlCommandInfo sql, ISessionImplementor session)
at NHibernate.Persister.Entity.AbstractEntityPersister.Update(Object id, Object[] fields, Int32[] dirtyFields, Boolean hasDirtyCollection, Object[] oldFields, Object oldVersion, Object obj, Object rowId, ISessionImplementor session)
at NHibernate.Action.EntityUpdateAction.Execute()
at NHibernate.Engine.ActionQueue.Execute(IExecutable executable)
at NHibernate.Engine.ActionQueue.ExecuteActions(IList list)
at NHibernate.Engine.ActionQueue.ExecuteActions()
at NHibernate.Event.Default.AbstractFlushingEventListener.PerformExecutions(IEventSource session)
at NHibernate.Event.Default.DefaultFlushEventListener.OnFlush(FlushEvent event)
at NHibernate.Impl.SessionImpl.Flush()
at NHibernate.Transaction.AdoTransaction.Commit()
at Rhino.Commons.NHibernateTransactionAdapter.Commit()
at Rhino.Commons.Facilities.RhinoTransactionResourceAdapter.Commit()
at Castle.Services.Transaction.AbstractTransaction.Commit()
--- End of inner exception stack trace ---
at Castle.Services.Transaction.AbstractTransaction.Commit()
at Castle.Services.Transaction.StandardTransaction.Commit()
at Castle.Facilities.AutomaticTransactionManagement.TransactionInterceptor.Intercept(IInvocation invocation)
at Castle.DynamicProxy.AbstractInvocation.Proceed()
at IReceiveServiceProxy61c28a82c9a24e96957e32292b924889.Save(Receive instance)
at WcfInterfaceService.MobileServices.SaveReceiveLines(IEnumerable1 receiveLines, String warehouseCode, String username, String deviceNumber, Boolean removeOldReceiveLines) in D:\Project Docs\Clients\ClientX 09.08\Projects\ProjectX\ProjectX.WcfInterfaceService\MobileServices.svc.cs:line 567
1 receiveLines, String warehouseCode, String username, String deviceNumber) in D:\Project Docs\Clients\ClientX 09.08\Projects\ProjectX\ProjectX.WcfInterfaceService\MobileServices.svc.cs:line 770
at WcfInterfaceService.MobileServices.ProcessReceiveResults(List
at WcfInterfaceService.MobileServices.ProcessResultsFromMobile(String receiveResult, String warehouseCode, String username, String deviceNumber) in D:\Project Docs\Clients\ClientX 09.08\Projects\ProjectX\ProjectX.WcfInterfaceService\MobileServices.svc.cs:line 668
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您运行的是 SQL Server 2008 吗?我今天在使用 SQL Server 2008 时遇到了同样的错误。在数据库上,我已将列设置为“日期”而不是“日期时间”,因为我不关心时间部分。但 .NET 中没有“日期”数据类型,因此您使用日期时间。
对我来说,我传递的是空日期时间值,默认为 1/1/0001 12:00:00 AM。所以我遇到了与您所看到的相同的错误,因为它包含时间部分。
对我来说,我必须使我的日期时间值可以为空,并且我还必须使用 NHibernate 中支持日期数据类型的 MsSql2008Dialect。有关 NHibernate 和 SQL Server 2008 此处。
如果您使用的是 SQL Server 2008,我会检查以确保您的数据库数据类型设置正确,并且您使用的是 MsSql2008Dialect。
Are you running SQL Server 2008? I ran into this same error today when using SQL Server 2008. On the database I had set the column to "date" instead of "datetime" because I do not care about the time portion. But there isn't a "date" data type in .NET so you use datetime.
For me I was passing along null datetime values which defaults to something like 1/1/0001 12:00:00 AM. So I was getting the same error you are seeing because it included the time portion.
For me I had to make my datetime value nullable and I also had to use the MsSql2008Dialect in NHibernate which supports the date datatype. More info about NHibernate and SQL Server 2008 here.
I'd check to make sure your database data type is set correctly and that you are using the MsSql2008Dialect if you are using SQL Server 2008.
在给你答案之前我有两个问题:
猜测:您使用的数据库的日期时间范围或准确性比您在代码中使用的数据库要小。在这种情况下,异常不是由 NHibernate 引起的,而是由数据库的某个功能引起的。这不是一个错误,而是一个功能。
I have two questions before I can give you an answer:
Guess: you are using a database that has a smaller datetime range or accuracy than you use in your code. In that case, the exception is not caused by NHibernate, but by a feature of the database. It's not a bug but a feature.