当参数上仅设置短日期时,SQL Server 2005 将 DateTime sproc 参数视为时间 12:00 PM
昨天,.NET 3.5 应用程序遇到了一个奇怪的问题。
我们有一个 Web 服务,可以调用搜索结果的存储过程。参数之一是日期。参数值为短日期字符串(M/d/yyyy、en-us),其类型为 DbType.DateTime。我使用 DbProviderFactory 连接到 SQL Server 2005,因此参数类型实际上变为 SqlDbType.DateTime。
通常,当我使用 SQL Server Profiler 观看通话时,我看到的日期为“yyyy-Md 00:00:00”。但是,昨天,由于一些报告的问题,我进行了分析,日期显示为“yyyy-Md 12:00:00:000”。基本上,一切都按预期运行,然后,在不更改我的代码的情况下,存储过程会看到中午 12:00。
这也发生在某些插入和更新上,导致中午 12 点与某些默认日期一起存储,而不是午夜 12 点。
没有更新我的代码,今天一切都很好。
我可以看到,当 DataAdapter 填充我的 DataTable 时,参数上的 CoercedValue 属性设置为“yyyy-Md 12:00:00 AM”,而值仅为“M/d/yyyy”。
所以,我的问题是:
是否有人对 DataAdapter(DbDataAdapter 或 SqlDataAdapter)有足够的了解,知道为什么当我只指定短日期作为存储过程参数的值时它会发送 12PM?
提前致谢!
Had a weird issue yesterday with a .NET 3.5 application.
We have a web service that calls a stored procedure for search results. One of the parameters is a date. The parameter value is a short date string (M/d/yyyy, en-us) and its type is DbType.DateTime. I am using DbProviderFactory connecting to SQL Server 2005, so the paramater type actually becomes SqlDbType.DateTime.
Normally, when I use SQL Server Profiler to watch the call, I see the date as "yyyy-M-d 00:00:00". But, yesterday, I was profiling due to some reported issues and the date appeared as "yyyy-M-d 12:00:00:000". Basically, everything has always worked as intended and then, without a change to my code, the stored procedure was seeing 12:00 PM.
This also happened on some inserts and updates causing 12PM to get stored with some default dates instead of 12AM, midnight.
Without updating my code, all is well today.
I can see that when the DataAdapter fills my DataTable, a CoercedValue property gets set on the parameter as "yyyy-M-d 12:00:00 AM" while the Value is only "M/d/yyyy".
So, my question is:
Does anyone know enough about the DataAdapter (DbDataAdapter or SqlDataAdapter) to know why it would be sending 12PM when I've only specified the short date as the value for the stored procedure parameter?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论