Postgresql 错误:字符串未被识别为有效的日期时间
当我尝试从 C# 的 postgresql 检索日期字段时,出现此错误。如从表中选择日期字段
。
运行 postgesql 的系统位于 IST 时区。我无法编辑数据库或部署数据库的系统上的任何设置。我可以在代码中做什么来防止这个问题?
更新:客户端位于 MST timzone 上。忘了说了。
更新2:附加代码
DbDataAdapter myAdapter = dbFactory.NewDataAdapter(sSQL, myConnection);
if (myConnection.State != ConnectionState.Open)
myConnection.Open();
ds = new DataSet();
myAdapter.Fill(ds, dataTableName);
I am getting this error when I try to retrieve a date field from postgresql from C#. As in select datefield from table
.
The system on which postgesql is running is on IST timezone. I can not edit any settings on the database or the system on which it is deployed. What can I do in my code to prevent this issue?
UPDATE: The client is on MST timzone. Forgot to mention that.
UPDTATE2 : Attaching code
DbDataAdapter myAdapter = dbFactory.NewDataAdapter(sSQL, myConnection);
if (myConnection.State != ConnectionState.Open)
myConnection.Open();
ds = new DataSet();
myAdapter.Fill(ds, dataTableName);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您确定在
DbDataAdapter
上使用有效的方言吗?你们工厂退回什么类型的?意思是,myAdapter.GetType()
返回什么?PostgreSQL 处理最小值/最大值的方式与大多数数据库略有不同,并且可能返回日期:
'-infinity'
对应于DateTime.MinValue
'infinity'
> forDateTime.MaxValue
除非您的适配器处理该问题,否则我猜您可能会遇到类似的错误。
我猜你应该使用 Npgsql-provider 中的
NpgsqlDataAdapter
,但你没有在某处提到它。编辑:发现有一个已知的错误: http://pgfoundry.org/forum/message .php?msg_id=1005522,但尚未发现这会影响哪些版本。它与半小时时区有关(例如+3:30)。我想这在 2.0.8 中也得到了修复。
http://pgfoundry.org/frs/shownotes.php?release_id=1686 2.0.10 中还存在一些 timestampTZ 修复
Are you sure you are using a valid dialect on your
DbDataAdapter
? What type does your factory return? Meaning, what doesmyAdapter.GetType()
return?PostgreSQL handles min/maxvalues a little different than most DBs, and might return dates as:
'-infinity'
corresponds toDateTime.MinValue
'infinity'
forDateTime.MaxValue
Unless your adapter handles that I guess you might end up with a similar error.
I'm guessing you should be using
NpgsqlDataAdapter
from the Npgsql-provider, but you don't mention it somewhere.EDIT: Found that there is a known bug: http://pgfoundry.org/forum/message.php?msg_id=1005522, but haven't found which versions this affect. It has to do with half hour timezones (e.g +3:30). I guess that is fixed in 2.0.8 as well.
http://pgfoundry.org/frs/shownotes.php?release_id=1686 some timestampTZ fixes was also present in 2.0.10
尝试将其作为字符串读取,然后在 C# 中将其解析为日期。
喜欢:
看看是否有效,可能只是格式错误。
但是,如果这没有帮助,您可以发布您的代码吗?
谢谢,
亚历克斯.
Try reading it as a string and then parsing it as a date in C#.
Like:
See if that works, could just be a format error.
However if this dosn't help, Could you please post your code.
Thanks,
Alex.