c# - PostgreSQL 错误 : String was not recognized as a valid date time

标签 c# postgresql

当我尝试从 C# 的 postgresql 中检索日期字段时出现此错误。如 从表中选择日期字段

运行 postgesql 的系统在 IST 时区。我无法编辑数据库或部署它的系统上的任何设置。我可以在我的代码中做些什么来防止这个问题?

更新:客户端在 MST 时区上。忘了说了。

UPDTATE2:附加代码

DbDataAdapter myAdapter = dbFactory.NewDataAdapter(sSQL, myConnection);
if (myConnection.State != ConnectionState.Open)
       myConnection.Open();   
ds = new DataSet();
myAdapter.Fill(ds, dataTableName);

最佳答案

您确定您在 DbDataAdapter 上使用的是有效方言吗?你们工厂返回是什么类型的?也就是说,myAdapter.GetType() 返回什么?

PostgreSQL 处理最小值/最大值的方式与大多数数据库略有不同,可能会返回日期:

  • '-infinity'对应DateTime.MinValue
  • 'infinity' for DateTime.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 修复

关于c# - PostgreSQL 错误 : String was not recognized as a valid date time,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5271524/

相关文章:

c# - 对于可观察的集合列表,检查LINQ返回是否为null

ruby-on-rails - 在 heroku 上部署 Rails 应用程序,不显示 SQL 查询

postgresql - 如何处理与 gorp 的连接?

sql - Postgres 动态列标题(来自另一个表)

c# - 自定义 Json.NET 序列化 : turning object into array to avoid repetition of property names

c# - Net Core 3 上的 Web Api 版本控制

c# - + 带空操作数的字符串连接运算符

c# - 在 Release模式下构建时发生 System.BadImageFormatException

postgresql - 受支持的 PHP 扩展(PgSQL、PDO_PgSQL)均不可用

postgresql - 使用 PostgreSQL 全文搜索匹配简短但重要的字符串