Cannot retrieve timestamp filed value from db (PostgreSQLDirect .NET 2.50.16)
Posted: Mon 21 Aug 2006 18:14
Dear Colleagues
I have been using PostgreSQLDirect .NET 2.50.16 + VS2005 Prof.
I am experiencing strange problem with getting data from timestamp field.
Initially I have been developing small application using Windows based Postgres 8.1 server (localhost). All was OK.
When I moved db to production Linux machine the problem surfaced.
Sample query to show the problem:
"SELECT id, date FROM orders WHERE id=6900"
Whne I query db directly in PgAdmin I get results:
id ; date
-------------------------------------------
6900 ; 2006-06-05 09:22:44.437441
Then I use following code in C#:
myPgConn = new PgSqlConnection(cnnStr);
myPgConn.Open();
PgSqlCommand cmd = new PgSqlCommand("SELECT id, date FROM orders WHERE id=6900");
cmd.Connection = myPgConn;
PgSqlDataReader rdr = cmd.ExecuteReader();
while (rdr.Read())
{
textBox1.AppendText( "Fld 1 type :" + rdr.GetDataTypeName(0).ToString());
textBox1.AppendText( "\nFld 1 value:" + rdr.GetValue(0).ToString());
textBox1.AppendText( "\nFld 2 type :" + rdr.GetDataTypeName(1).ToString());
textBox1.AppendText( "\nFld 2 value:" + rdr.GetValue(1).ToString() + "\n");
}
rdr.Close();
This code returns following results:
Fld 1 type :BIGINT
Fld 1 value:6900
Fld 2 type :TIMESTAMP
Fld 2 value:2000-01-01 00:00:00 <-- Not correct !
I use protocol version ProtocolVersion.Ver30 (in PgSqlConnectionStringBuilder - not shown in example)
When I switch to Ver20 problem is eliminated - the code returns values:
Fld 1 type :BIGINT
Fld 1 value:6900
Fld 2 type :TIMESTAMP
Fld 2 value:2006-06-05 09:22:44 <-- Correct !
Db is ver. Postgres 8.1 on Linux (Ubuntu 6) machine.
Entries in postgres.conf:
...
datestyle = 'iso, dmy'
client_encoding = unicode
lc_messages = 'pl_PL.UTF-8'
lc_monetary = 'pl_PL.UTF-8' # locale for monetaryformatting
lc_numeric = 'pl_PL.UTF-8' # locale for number formatting
lc_time = 'pl_PL.UTF-8' # locale for time formatting
Suppose if I do not want to switch to protocol Ver30 how can I get rid of this problem ?
Appreciate your comments.
Best regards,
Wojtek Pawlowski
I have been using PostgreSQLDirect .NET 2.50.16 + VS2005 Prof.
I am experiencing strange problem with getting data from timestamp field.
Initially I have been developing small application using Windows based Postgres 8.1 server (localhost). All was OK.
When I moved db to production Linux machine the problem surfaced.
Sample query to show the problem:
"SELECT id, date FROM orders WHERE id=6900"
Whne I query db directly in PgAdmin I get results:
id ; date
-------------------------------------------
6900 ; 2006-06-05 09:22:44.437441
Then I use following code in C#:
myPgConn = new PgSqlConnection(cnnStr);
myPgConn.Open();
PgSqlCommand cmd = new PgSqlCommand("SELECT id, date FROM orders WHERE id=6900");
cmd.Connection = myPgConn;
PgSqlDataReader rdr = cmd.ExecuteReader();
while (rdr.Read())
{
textBox1.AppendText( "Fld 1 type :" + rdr.GetDataTypeName(0).ToString());
textBox1.AppendText( "\nFld 1 value:" + rdr.GetValue(0).ToString());
textBox1.AppendText( "\nFld 2 type :" + rdr.GetDataTypeName(1).ToString());
textBox1.AppendText( "\nFld 2 value:" + rdr.GetValue(1).ToString() + "\n");
}
rdr.Close();
This code returns following results:
Fld 1 type :BIGINT
Fld 1 value:6900
Fld 2 type :TIMESTAMP
Fld 2 value:2000-01-01 00:00:00 <-- Not correct !
I use protocol version ProtocolVersion.Ver30 (in PgSqlConnectionStringBuilder - not shown in example)
When I switch to Ver20 problem is eliminated - the code returns values:
Fld 1 type :BIGINT
Fld 1 value:6900
Fld 2 type :TIMESTAMP
Fld 2 value:2006-06-05 09:22:44 <-- Correct !
Db is ver. Postgres 8.1 on Linux (Ubuntu 6) machine.
Entries in postgres.conf:
...
datestyle = 'iso, dmy'
client_encoding = unicode
lc_messages = 'pl_PL.UTF-8'
lc_monetary = 'pl_PL.UTF-8' # locale for monetaryformatting
lc_numeric = 'pl_PL.UTF-8' # locale for number formatting
lc_time = 'pl_PL.UTF-8' # locale for time formatting
Suppose if I do not want to switch to protocol Ver30 how can I get rid of this problem ?
Appreciate your comments.
Best regards,
Wojtek Pawlowski