Can't convert infinite timestamp values to DateTime

See original GitHub issue

I’m trying to read database table where few columns are of ‘timestamp without time zone’ Datatype. when trying to read is into dataset I’m getting ‘InvalidCastError’. Column value in database is in YYYY-MM-DD HH:MM:SS format.

query I’m running is

string sql = "SELECT * FROM simple_table";
            NpgsqlDataAdapter da = new NpgsqlDataAdapter(sql, conn);
            ds.Reset();
            da.Fill(ds);

Environment NPGSQL version 3.0.5 Dotnet framework 4.5 Visual studio 2012 web xpress

I’ve seen similar issue reported before, but I can’t get a solution.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
shortspidercommented, May 9, 2016

I ran the following code using:

  • Npgsql 3.0.5
  • .NET 4.5
  • Postgres 9.4

The following was run in pgAdmin:

CREATE DATABASE "1028_test"
  WITH OWNER = postgres
       ENCODING = 'UTF8'
       TABLESPACE = pg_default
       LC_COLLATE = 'English_United States.1252'
       LC_CTYPE = 'English_United States.1252'
       CONNECTION LIMIT = -1;

CREATE TABLE test_table
(
  iid serial NOT NULL,
  dttimestamp timestamp without time zone,
  CONSTRAINT pk_test_table PRIMARY KEY (iid)
)
WITH (
  OIDS=FALSE
);
ALTER TABLE test_table
  OWNER TO postgres;

INSERT INTO test_table (dttimestamp) VALUES ('2016-01-01 00:12:00');

And then this was run in C#:

var dataSet = new DataSet();
var connectionString = "your connection string";
using (var connection = new NpgsqlConnection(connectionString))
{
    using (var dataAdapter = new NpgsqlDataAdapter("SELECT * FROM test_table", connection))
    {
        dataSet.Reset();
        dataAdapter.Fill(dataSet);
    }
}

This code completed with no issues, no exception was thrown. @dhnnjy can you post a little more code that generates the exception for you? I admittedly do not use DataSets or DataAdapters so perhaps I’m doing something wrong here.

0reactions
rojicommented, Jun 8, 2018

Close for age, Convert Infinity DateTime should be the solution to this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can't convert infinite timestamp values to DateTime ...
I am doing a fetch on a User entity and it is returning 'Can't convert infinite timestamp values to DateTime' An exception of...
Read more >
c# - Why does setting a nulalble DateTime to ...
The problem lies within your C# code. According to MSDN: The DateTime.MaxValue field represents the largest possible value of DateTime ...
Read more >
Thread: Problems with infinity - Postgres Professional
I can't change the database content because several stored procedures are based on infinite timestamp values. Of course I understand that conversion ......
Read more >
Date and Time Handling
PostgreSQL supports the special values -infinity and infinity for the timestamp and date types (see docs); these can be useful to represent a...
Read more >
Can't convert infinite timestamp values to DateTime
I'm trying to read database table where few columns are of 'timestamp without time zone' Datatype. when trying to read is into dataset...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found