pg.ddx.io pgsql-odbc@postgresql.org mailing list archive
help / color / mirror / Atom feedODBC connections go dead after a failed query?
6+ messages / 3 participants
[nested] [flat]
* ODBC connections go dead after a failed query?
@ 2017-03-03 20:14 Jack C. Wei <jackcwei+pgsql@gmail.com>
0 siblings, 2 replies; 6+ messages in thread
From: Jack C. Wei @ 2017-03-03 20:14 UTC (permalink / raw)
To: pgsql-odbc
Hi,
We have some legacy SQL queries that works on SQL Server but not on
PostgreSQL due to SQL Server-specific syntax, which we are working to
migrate. The problem is sometimes psqlodbc just cannot seem to reset itself
after a bad query and simply go dead. All subsequent queries on the same
connection, legitimate or not, would fail.
I've verified this can happen with the latest PostgreSQL 9.6.2 and psqlodbc
09_06_0100, on a Windows 7 x64 host.
The offending SQL query is something like "UPDATE site SET
image=image_old;" where [image] is BYTEA (used to be MEDIUMBLOB on SQL
Server) and [image_old] is TEXT. PostgreSQL does not allow this, which is
understandable. But after this query the connection goes dead, failing all
subsequent queries with ODBC error 08S01 or HY000. While it is possible to
detect this and reconnect as a workaround, it would be cumbersome and lead
to unwarranted overhead. See the following excerpt from my ODBC trace log:
PsqlOdbcBug f68-e10 EXIT SQLPrepareW with return code 0
(SQL_SUCCESS)
HSTMT 0x00033EE8
WCHAR * 0x010F0F28 [ -3] "UPDATE site SET
image=image_old;\ 0"
SDWORD -3
PsqlOdbcBug f68-e10 ENTER SQLExecute
HSTMT 0x00033EE8
PsqlOdbcBug f68-e10 EXIT SQLExecute with return code -1 (SQL_ERROR)
HSTMT 0x00033EE8
DIAG [42804] ERROR: column "image" is of type bytea but expression
is of type text;
Error while preparing parameters (1)
PsqlOdbcBug f68-e10 ENTER SQLFreeHandle
SQLSMALLINT 3 <SQL_HANDLE_STMT>
SQLHANDLE 0x00033EE8
PsqlOdbcBug f68-e10 EXIT SQLFreeHandle with return code 0
(SQL_SUCCESS)
SQLSMALLINT 3 <SQL_HANDLE_STMT>
SQLHANDLE 0x00033EE8
PsqlOdbcBug f68-e10 ENTER SQLAllocHandle
SQLSMALLINT 3 <SQL_HANDLE_STMT>
SQLHANDLE 0x000338D8
SQLHANDLE * 0x0035EB90
PsqlOdbcBug f68-e10 EXIT SQLAllocHandle with return code 0
(SQL_SUCCESS)
SQLSMALLINT 3 <SQL_HANDLE_STMT>
SQLHANDLE 0x000338D8
SQLHANDLE * 0x0035EB90 ( 0x00D51C98)
PsqlOdbcBug f68-e10 ENTER SQLPrepareW
HSTMT 0x00D51C98
WCHAR * 0x010F0DE0 [ -3] "SELECT id FROM site;\ 0"
SDWORD -3
PsqlOdbcBug f68-e10 EXIT SQLPrepareW with return code 0
(SQL_SUCCESS)
HSTMT 0x00D51C98
WCHAR * 0x010F0DE0 [ -3] "SELECT id FROM site;\ 0"
SDWORD -3
PsqlOdbcBug f68-e10 ENTER SQLExecute
HSTMT 0x00D51C98
PsqlOdbcBug f68-e10 EXIT SQLExecute with return code -1 (SQL_ERROR)
HSTMT 0x00D51C98
DIAG [08S01] Could not send Query(connection dead);
Could not send Query(connection dead) (26)
I've attached a minimal working sample code (we develop in Visual Studio
2013) and also the ODBC trace log. Hopefully they make it through. Any
feedback is welcome.
Thank you,
Jack Wei
--
Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-odbc
Attachments:
SQL2.LOG (application/octet-stream, 14.6K) download
psqlodbcbug.cpp (text/x-c++src, 2.2K) download
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#endif
#include <sql.h>
#include <sqlext.h>
#include <sqltypes.h>
#include <iostream>
#include <string>
using namespace std;
static bool execSQL( SQLHDBC hdbc, const wchar_t* sql )
{
SQLHSTMT hstmt = SQL_NULL_HSTMT;
SQLRETURN status = SQLAllocHandle( SQL_HANDLE_STMT, hdbc, &hstmt );
status = SQLPrepareW( hstmt, const_cast< wchar_t* >( sql ), SQL_NTS );
status = SQLExecute( hstmt );
bool ok = SQL_SUCCEEDED( status ) || status == SQL_NO_DATA;
if ( !ok )
{
wcerr << L"Unable to execute the SQL statement:" << endl << sql << endl;
SQLRETURN rc;
SQLWCHAR state[6], msg[4096];
SQLINTEGER native;
SQLSMALLINT msgLen;
for ( SQLSMALLINT i = 1; ( rc = SQLGetDiagRecW( SQL_HANDLE_STMT, hstmt, i, state, &native, msg, 4096, &msgLen ) ) != SQL_NO_DATA; ++i )
if ( rc == SQL_SUCCESS )
wcerr << L"[" << i << L"] " << state << L"(" << native << L"): " << msg << endl;
wcerr << endl;
}
status = SQLFreeHandle( SQL_HANDLE_STMT, hstmt );
return ok;
}
int main( int argc, char** argv )
{
SQLHANDLE henv = SQL_NULL_HENV;
SQLRETURN status = SQLAllocHandle( SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv );
status = SQLSetEnvAttr( henv, SQL_ATTR_ODBC_VERSION, (SQLPOINTER)SQL_OV_ODBC3, 0 );
SQLHANDLE hdbc = SQL_NULL_HDBC;
status = SQLAllocHandle( SQL_HANDLE_DBC, henv, &hdbc );
status = SQLSetConnectAttrW( hdbc, SQL_LOGIN_TIMEOUT, (SQLPOINTER)5, 0 );
wchar_t* connectionString = L"DRIVER={PostgreSQL UNICODE};SERVER=localhost;PORT=5432;"
L"UID=arguser;PWD=CSMCnm42!!;DATABASE=arg;ByteaAsLongVarBinary=1;"
L"UseDeclareFetch=1;";
wchar_t outbuf[2048];
SQLSMALLINT outlen = 0;
status = SQLDriverConnectW( hdbc, NULL, connectionString, wcslen( connectionString ),
outbuf, 2048, &outlen, SQL_DRIVER_NOPROMPT );
execSQL( hdbc, L"DROP TABLE IF EXISTS site;" );
execSQL( hdbc, L"CREATE TABLE site (id SERIAL PRIMARY KEY, name VARCHAR(64), image_old TEXT, image BYTEA);" );
execSQL( hdbc, L"UPDATE site SET image=image_old;" );
execSQL( hdbc, L"SELECT id FROM site;" );
execSQL( hdbc, L"SELECT name FROM site;" );
SQLDisconnect( hdbc );
SQLFreeHandle( SQL_HANDLE_DBC, hdbc );
SQLFreeHandle( SQL_HANDLE_ENV, henv );
return 0;
}
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: ODBC connections go dead after a failed query?
@ 2017-03-03 20:27 Adrian Klaver <adrian.klaver@aklaver.com>
parent: Jack C. Wei <jackcwei+pgsql@gmail.com>
1 sibling, 1 reply; 6+ messages in thread
From: Adrian Klaver @ 2017-03-03 20:27 UTC (permalink / raw)
To: Jack C. Wei <jackcwei+pgsql@gmail.com>; pgsql-odbc
On 03/03/2017 12:14 PM, Jack C. Wei wrote:
> Hi,
>
> We have some legacy SQL queries that works on SQL Server but not on
> PostgreSQL due to SQL Server-specific syntax, which we are working to
> migrate. The problem is sometimes psqlodbc just cannot seem to reset
> itself after a bad query and simply go dead. All subsequent queries on
> the same connection, legitimate or not, would fail.
>
> I've verified this can happen with the latest PostgreSQL 9.6.2 and
> psqlodbc 09_06_0100, on a Windows 7 x64 host.
>
> The offending SQL query is something like "UPDATE site SET
> image=image_old;" where [image] is BYTEA (used to be MEDIUMBLOB on SQL
> Server) and [image_old] is TEXT. PostgreSQL does not allow this, which
> is understandable. But after this query the connection goes dead,
> failing all subsequent queries with ODBC error 08S01 or HY000. While it
> is possible to detect this and reconnect as a workaround, it would be
> cumbersome and lead to unwarranted overhead. See the following excerpt
> from my ODBC trace log:
>
>
> PsqlOdbcBug f68-e10 EXIT SQLPrepareW with return code 0
> (SQL_SUCCESS)
> HSTMT 0x00033EE8
> WCHAR * 0x010F0F28 [ -3] "UPDATE site SET
> image=image_old;\ 0"
> SDWORD -3
>
> PsqlOdbcBug f68-e10 ENTER SQLExecute
> HSTMT 0x00033EE8
>
> PsqlOdbcBug f68-e10 EXIT SQLExecute with return code -1 (SQL_ERROR)
> HSTMT 0x00033EE8
>
> DIAG [42804] ERROR: column "image" is of type bytea but
> expression is of type text;
> Error while preparing parameters (1)
>
> PsqlOdbcBug f68-e10 ENTER SQLFreeHandle
> SQLSMALLINT 3 <SQL_HANDLE_STMT>
> SQLHANDLE 0x00033EE8
>
> PsqlOdbcBug f68-e10 EXIT SQLFreeHandle with return code 0
> (SQL_SUCCESS)
> SQLSMALLINT 3 <SQL_HANDLE_STMT>
> SQLHANDLE 0x00033EE8
>
> PsqlOdbcBug f68-e10 ENTER SQLAllocHandle
> SQLSMALLINT 3 <SQL_HANDLE_STMT>
> SQLHANDLE 0x000338D8
> SQLHANDLE * 0x0035EB90
>
> PsqlOdbcBug f68-e10 EXIT SQLAllocHandle with return code 0
> (SQL_SUCCESS)
> SQLSMALLINT 3 <SQL_HANDLE_STMT>
> SQLHANDLE 0x000338D8
> SQLHANDLE * 0x0035EB90 ( 0x00D51C98)
>
> PsqlOdbcBug f68-e10 ENTER SQLPrepareW
> HSTMT 0x00D51C98
> WCHAR * 0x010F0DE0 [ -3] "SELECT id FROM site;\ 0"
> SDWORD -3
>
> PsqlOdbcBug f68-e10 EXIT SQLPrepareW with return code 0
> (SQL_SUCCESS)
> HSTMT 0x00D51C98
> WCHAR * 0x010F0DE0 [ -3] "SELECT id FROM site;\ 0"
> SDWORD -3
>
> PsqlOdbcBug f68-e10 ENTER SQLExecute
> HSTMT 0x00D51C98
>
> PsqlOdbcBug f68-e10 EXIT SQLExecute with return code -1 (SQL_ERROR)
> HSTMT 0x00D51C98
>
> DIAG [08S01] Could not send Query(connection dead);
> Could not send Query(connection dead) (26)
>
>
> I've attached a minimal working sample code (we develop in Visual Studio
> 2013) and also the ODBC trace log. Hopefully they make it through. Any
> feedback is welcome.
I am betting you dealing with something like this:
test=> begin ;
BEGIN
test=> select 1/0;
ERROR: division by zero
test=> select 1;
ERROR: current transaction is aborted, commands ignored until end of
transaction block
test=> rollback ;
ROLLBACK
test=> select 1;
?column?
----------
1
(1 row)
Basically an error in a transaction stops everything until you rollback.
Here:
https://odbc.postgresql.org/docs/config.html
there is :
Level of rollback on errors: Specifies what to rollback should an error
occur.
Nop(0): Don't rollback anything and let the application handle the
error.
Transaction(1): Rollback the entire transaction.
Statement(2): Rollback the statement.
Notes in a setup: This specification is set up with a PROTOCOL
option parameter.
PROTOCOL=[6.2|6.3|6.4|7.4][-(0|1|2)]
default value is a sentence unit (it is a transaction unit before 8.0).
I have never used that, so I am not sure exactly how to invoke it and
what the consequences are.
>
>
> Thank you,
> Jack Wei
>
>
>
>
>
--
Adrian Klaver
adrian.klaver@aklaver.com
--
Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-odbc
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: ODBC connections go dead after a failed query?
@ 2017-03-03 21:53 Jack C. Wei <jackcwei+pgsql@gmail.com>
parent: Adrian Klaver <adrian.klaver@aklaver.com>
0 siblings, 0 replies; 6+ messages in thread
From: Jack C. Wei @ 2017-03-03 21:53 UTC (permalink / raw)
To: Adrian Klaver <adrian.klaver@aklaver.com>; +Cc: pgsql-odbc
Adrian, thanks for the reply.
Unfortunately I don't think it's about transactions. We do not use
transactions in our queries, which means neither BEGIN/ROLLBACK/COMMIT nor
ODBC's SQLEndTran().
I also tried the different rollback levels you mentioned by using
"PROTOCOL=7.4-0" or -1 or -2. None of them make a difference.
On Fri, Mar 3, 2017 at 12:27 PM, Adrian Klaver <adrian.klaver@aklaver.com>
wrote:
> On 03/03/2017 12:14 PM, Jack C. Wei wrote:
>
>> Hi,
>>
>> We have some legacy SQL queries that works on SQL Server but not on
>> PostgreSQL due to SQL Server-specific syntax, which we are working to
>> migrate. The problem is sometimes psqlodbc just cannot seem to reset
>> itself after a bad query and simply go dead. All subsequent queries on
>> the same connection, legitimate or not, would fail.
>>
>> I've verified this can happen with the latest PostgreSQL 9.6.2 and
>> psqlodbc 09_06_0100, on a Windows 7 x64 host.
>>
>> The offending SQL query is something like "UPDATE site SET
>> image=image_old;" where [image] is BYTEA (used to be MEDIUMBLOB on SQL
>> Server) and [image_old] is TEXT. PostgreSQL does not allow this, which
>> is understandable. But after this query the connection goes dead,
>> failing all subsequent queries with ODBC error 08S01 or HY000. While it
>> is possible to detect this and reconnect as a workaround, it would be
>> cumbersome and lead to unwarranted overhead. See the following excerpt
>> from my ODBC trace log:
>>
>>
>> PsqlOdbcBug f68-e10 EXIT SQLPrepareW with return code 0
>> (SQL_SUCCESS)
>> HSTMT 0x00033EE8
>> WCHAR * 0x010F0F28 [ -3] "UPDATE site SET
>> image=image_old;\ 0"
>> SDWORD -3
>>
>> PsqlOdbcBug f68-e10 ENTER SQLExecute
>> HSTMT 0x00033EE8
>>
>> PsqlOdbcBug f68-e10 EXIT SQLExecute with return code -1
>> (SQL_ERROR)
>> HSTMT 0x00033EE8
>>
>> DIAG [42804] ERROR: column "image" is of type bytea but
>> expression is of type text;
>> Error while preparing parameters (1)
>>
>> PsqlOdbcBug f68-e10 ENTER SQLFreeHandle
>> SQLSMALLINT 3 <SQL_HANDLE_STMT>
>> SQLHANDLE 0x00033EE8
>>
>> PsqlOdbcBug f68-e10 EXIT SQLFreeHandle with return code 0
>> (SQL_SUCCESS)
>> SQLSMALLINT 3 <SQL_HANDLE_STMT>
>> SQLHANDLE 0x00033EE8
>>
>> PsqlOdbcBug f68-e10 ENTER SQLAllocHandle
>> SQLSMALLINT 3 <SQL_HANDLE_STMT>
>> SQLHANDLE 0x000338D8
>> SQLHANDLE * 0x0035EB90
>>
>> PsqlOdbcBug f68-e10 EXIT SQLAllocHandle with return code 0
>> (SQL_SUCCESS)
>> SQLSMALLINT 3 <SQL_HANDLE_STMT>
>> SQLHANDLE 0x000338D8
>> SQLHANDLE * 0x0035EB90 ( 0x00D51C98)
>>
>> PsqlOdbcBug f68-e10 ENTER SQLPrepareW
>> HSTMT 0x00D51C98
>> WCHAR * 0x010F0DE0 [ -3] "SELECT id FROM site;\
>> 0"
>> SDWORD -3
>>
>> PsqlOdbcBug f68-e10 EXIT SQLPrepareW with return code 0
>> (SQL_SUCCESS)
>> HSTMT 0x00D51C98
>> WCHAR * 0x010F0DE0 [ -3] "SELECT id FROM site;\
>> 0"
>> SDWORD -3
>>
>> PsqlOdbcBug f68-e10 ENTER SQLExecute
>> HSTMT 0x00D51C98
>>
>> PsqlOdbcBug f68-e10 EXIT SQLExecute with return code -1
>> (SQL_ERROR)
>> HSTMT 0x00D51C98
>>
>> DIAG [08S01] Could not send Query(connection dead);
>> Could not send Query(connection dead) (26)
>>
>>
>> I've attached a minimal working sample code (we develop in Visual Studio
>> 2013) and also the ODBC trace log. Hopefully they make it through. Any
>> feedback is welcome.
>>
>
> I am betting you dealing with something like this:
>
> test=> begin ;
> BEGIN
> test=> select 1/0;
> ERROR: division by zero
> test=> select 1;
> ERROR: current transaction is aborted, commands ignored until end of
> transaction block
> test=> rollback ;
> ROLLBACK
> test=> select 1;
> ?column?
> ----------
> 1
> (1 row)
>
> Basically an error in a transaction stops everything until you rollback.
>
> Here:
> https://odbc.postgresql.org/docs/config.html
>
> there is :
>
> Level of rollback on errors: Specifies what to rollback should an error
> occur.
>
>
> Nop(0): Don't rollback anything and let the application handle the
> error.
>
> Transaction(1): Rollback the entire transaction.
>
> Statement(2): Rollback the statement.
>
>
> Notes in a setup: This specification is set up with a PROTOCOL option
> parameter.
>
> PROTOCOL=[6.2|6.3|6.4|7.4][-(0|1|2)]
> default value is a sentence unit (it is a transaction unit before 8.0).
>
> I have never used that, so I am not sure exactly how to invoke it and
> what the consequences are.
>
>
>
>
>>
>> Thank you,
>> Jack Wei
>>
>>
>>
>>
>>
>>
>
> --
> Adrian Klaver
> adrian.klaver@aklaver.com
>
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: ODBC connections go dead after a failed query?
@ 2017-03-04 13:48 Inoue, Hiroshi <h-inoue@dream.email.ne.jp>
parent: Jack C. Wei <jackcwei+pgsql@gmail.com>
1 sibling, 1 reply; 6+ messages in thread
From: Inoue, Hiroshi @ 2017-03-04 13:48 UTC (permalink / raw)
To: Jack C. Wei <jackcwei+pgsql@gmail.com>; +Cc: pgsql-odbc
Hi Jack,
Probably I found the cause.
Could you try the test drivers 9.6.0102 at
http://www.ne.jp/asahi/inocchichichi/entrance/psqlodbc/
?
regards,
Hiroshi Inoue
On 2017/03/04 5:14, Jack C. Wei wrote:
> Hi,
>
> We have some legacy SQL queries that works on SQL Server but not on
> PostgreSQL due to SQL Server-specific syntax, which we are working to
> migrate. The problem is sometimes psqlodbc just cannot seem to reset
> itself after a bad query and simply go dead. All subsequent queries on
> the same connection, legitimate or not, would fail.
>
> I've verified this can happen with the latest PostgreSQL 9.6.2 and
> psqlodbc 09_06_0100, on a Windows 7 x64 host.
>
> The offending SQL query is something like "UPDATE site SET
> image=image_old;" where [image] is BYTEA (used to be MEDIUMBLOB on SQL
> Server) and [image_old] is TEXT. PostgreSQL does not allow this, which
> is understandable. But after this query the connection goes dead,
> failing all subsequent queries with ODBC error 08S01 or HY000. While
> it is possible to detect this and reconnect as a workaround, it would
> be cumbersome and lead to unwarranted overhead. See the following
> excerpt from my ODBC trace log:
>
>
> PsqlOdbcBug f68-e10 EXIT SQLPrepareW with return code 0
> (SQL_SUCCESS)
> HSTMT 0x00033EE8
> WCHAR * 0x010F0F28 [ -3] "UPDATE site SET
> image=image_old
> ;\ 0"
> SDWORD -3
>
> PsqlOdbcBug f68-e10 ENTER SQLExecute
> HSTMT 0x00033EE8
>
> PsqlOdbcBug f68-e10 EXIT SQLExecute with return code -1
> (SQL_ERROR)
> HSTMT 0x00033EE8
>
> DIAG [42804] ERROR: column "image" is of type bytea but
> expression is of type text;
> Error while preparing parameters (1)
>
> PsqlOdbcBug f68-e10 ENTER SQLFreeHandle
> SQLSMALLINT 3 <SQL_HANDLE_STMT>
> SQLHANDLE 0x00033EE8
>
> PsqlOdbcBug f68-e10 EXIT SQLFreeHandle with return code 0
> (SQL_SUCCESS)
> SQLSMALLINT 3 <SQL_HANDLE_STMT>
> SQLHANDLE 0x00033EE8
>
> PsqlOdbcBug f68-e10 ENTER SQLAllocHandle
> SQLSMALLINT 3 <SQL_HANDLE_STMT>
> SQLHANDLE 0x000338D8
> SQLHANDLE * 0x0035EB90
>
> PsqlOdbcBug f68-e10 EXIT SQLAllocHandle with return code 0
> (SQL_SUCCESS)
> SQLSMALLINT 3 <SQL_HANDLE_STMT>
> SQLHANDLE 0x000338D8
> SQLHANDLE * 0x0035EB90 ( 0x00D51C98)
>
> PsqlOdbcBug f68-e10 ENTER SQLPrepareW
> HSTMT 0x00D51C98
> WCHAR * 0x010F0DE0 [ -3] "SELECT id FROM
> site;\ 0"
> SDWORD -3
>
> PsqlOdbcBug f68-e10 EXIT SQLPrepareW with return code 0
> (SQL_SUCCESS)
> HSTMT 0x00D51C98
> WCHAR * 0x010F0DE0 [ -3] "SELECT id FROM
> site;\ 0"
> SDWORD -3
>
> PsqlOdbcBug f68-e10 ENTER SQLExecute
> HSTMT 0x00D51C98
>
> PsqlOdbcBug f68-e10 EXIT SQLExecute with return code -1
> (SQL_ERROR)
> HSTMT 0x00D51C98
>
> DIAG [08S01] Could not send Query(connection dead);
> Could not send Query(connection dead) (26)
>
>
> I've attached a minimal working sample code (we develop in Visual
> Studio 2013) and also the ODBC trace log. Hopefully they make it
> through. Any feedback is welcome.
>
>
> Thank you,
> Jack Wei
>
--
Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-odbc
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: ODBC connections go dead after a failed query?
@ 2017-03-07 22:10 Jack C. Wei <jackcwei+pgsql@gmail.com>
parent: Inoue, Hiroshi <h-inoue@dream.email.ne.jp>
0 siblings, 1 reply; 6+ messages in thread
From: Jack C. Wei @ 2017-03-07 22:10 UTC (permalink / raw)
To: Inoue, Hiroshi <h-inoue@dream.email.ne.jp>; +Cc: pgsql-odbc
Hi Hiroshi,
I just tried the test driver 9.6.0102 and it seems to have fixed the bug.
Thank you for the good work.
When can we expect an official release of the new driver? We're looking to
deploy PostgreSQL in six weeks. Currently I'm using 9.3.0400 which is the
last official version that does not have this issue. 9.5.0100 starts having
this problem. So is 9.5.0400 and 9.6.0100 that I tried.
Regards,
Jack
On Sat, Mar 4, 2017 at 5:48 AM, Inoue, Hiroshi <h-inoue@dream.email.ne.jp>
wrote:
> Hi Jack,
>
> Probably I found the cause.
> Could you try the test drivers 9.6.0102 at
> http://www.ne.jp/asahi/inocchichichi/entrance/psqlodbc/
> ?
>
> regards,
> Hiroshi Inoue
>
>
> On 2017/03/04 5:14, Jack C. Wei wrote:
>
>> Hi,
>>
>> We have some legacy SQL queries that works on SQL Server but not on
>> PostgreSQL due to SQL Server-specific syntax, which we are working to
>> migrate. The problem is sometimes psqlodbc just cannot seem to reset itself
>> after a bad query and simply go dead. All subsequent queries on the same
>> connection, legitimate or not, would fail.
>>
>> I've verified this can happen with the latest PostgreSQL 9.6.2 and
>> psqlodbc 09_06_0100, on a Windows 7 x64 host.
>>
>> The offending SQL query is something like "UPDATE site SET
>> image=image_old;" where [image] is BYTEA (used to be MEDIUMBLOB on SQL
>> Server) and [image_old] is TEXT. PostgreSQL does not allow this, which is
>> understandable. But after this query the connection goes dead, failing all
>> subsequent queries with ODBC error 08S01 or HY000. While it is possible to
>> detect this and reconnect as a workaround, it would be cumbersome and lead
>> to unwarranted overhead. See the following excerpt from my ODBC trace log:
>>
>>
>> PsqlOdbcBug f68-e10 EXIT SQLPrepareW with return code 0
>> (SQL_SUCCESS)
>> HSTMT 0x00033EE8
>> WCHAR * 0x010F0F28 [ -3] "UPDATE site SET
>> image=image_old
>>
>
> ;\ 0"
>> SDWORD -3
>>
>> PsqlOdbcBug f68-e10 ENTER SQLExecute
>> HSTMT 0x00033EE8
>>
>> PsqlOdbcBug f68-e10 EXIT SQLExecute with return code -1
>> (SQL_ERROR)
>> HSTMT 0x00033EE8
>>
>> DIAG [42804] ERROR: column "image" is of type bytea but
>> expression is of type text;
>> Error while preparing parameters (1)
>>
>> PsqlOdbcBug f68-e10 ENTER SQLFreeHandle
>> SQLSMALLINT 3 <SQL_HANDLE_STMT>
>> SQLHANDLE 0x00033EE8
>>
>> PsqlOdbcBug f68-e10 EXIT SQLFreeHandle with return code 0
>> (SQL_SUCCESS)
>> SQLSMALLINT 3 <SQL_HANDLE_STMT>
>> SQLHANDLE 0x00033EE8
>>
>> PsqlOdbcBug f68-e10 ENTER SQLAllocHandle
>> SQLSMALLINT 3 <SQL_HANDLE_STMT>
>> SQLHANDLE 0x000338D8
>> SQLHANDLE * 0x0035EB90
>>
>> PsqlOdbcBug f68-e10 EXIT SQLAllocHandle with return code 0
>> (SQL_SUCCESS)
>> SQLSMALLINT 3 <SQL_HANDLE_STMT>
>> SQLHANDLE 0x000338D8
>> SQLHANDLE * 0x0035EB90 ( 0x00D51C98)
>>
>> PsqlOdbcBug f68-e10 ENTER SQLPrepareW
>> HSTMT 0x00D51C98
>> WCHAR * 0x010F0DE0 [ -3] "SELECT id FROM site;\
>> 0"
>> SDWORD -3
>>
>> PsqlOdbcBug f68-e10 EXIT SQLPrepareW with return code 0
>> (SQL_SUCCESS)
>> HSTMT 0x00D51C98
>> WCHAR * 0x010F0DE0 [ -3] "SELECT id FROM site;\
>> 0"
>> SDWORD -3
>>
>> PsqlOdbcBug f68-e10 ENTER SQLExecute
>> HSTMT 0x00D51C98
>>
>> PsqlOdbcBug f68-e10 EXIT SQLExecute with return code -1
>> (SQL_ERROR)
>> HSTMT 0x00D51C98
>>
>> DIAG [08S01] Could not send Query(connection dead);
>> Could not send Query(connection dead) (26)
>>
>>
>> I've attached a minimal working sample code (we develop in Visual Studio
>> 2013) and also the ODBC trace log. Hopefully they make it through. Any
>> feedback is welcome.
>>
>>
>> Thank you,
>> Jack Wei
>>
>>
>
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: ODBC connections go dead after a failed query?
@ 2017-03-08 10:53 Inoue, Hiroshi <h-inoue@dream.email.ne.jp>
parent: Jack C. Wei <jackcwei+pgsql@gmail.com>
0 siblings, 0 replies; 6+ messages in thread
From: Inoue, Hiroshi @ 2017-03-08 10:53 UTC (permalink / raw)
To: Jack C. Wei <jackcwei+pgsql@gmail.com>; +Cc: pgsql-odbc
Hi Jack,
On 2017/03/08 7:10, Jack C. Wei wrote:
> Hi Hiroshi,
>
> I just tried the test driver 9.6.0102 and it seems to have fixed the
> bug. Thank you for the good work.
>
> When can we expect an official release of the new driver? We're
> looking to deploy PostgreSQL in six weeks. Currently I'm using
> 9.3.0400 which is the last official version that does not have this
> issue. 9.5.0100 starts having this problem. So is 9.5.0400 and
> 9.6.0100 that I tried.
Probably we would make a new release in 10 days.
regards,
Hiroshi Inoue
>
> Regards,
> Jack
>
>
> On Sat, Mar 4, 2017 at 5:48 AM, Inoue, Hiroshi
> <h-inoue@dream.email.ne.jp <mailto:h-inoue@dream.email.ne.jp>> wrote:
>
> Hi Jack,
>
> Probably I found the cause.
> Could you try the test drivers 9.6.0102 at
> http://www.ne.jp/asahi/inocchichichi/entrance/psqlodbc/
> <http://www.ne.jp/asahi/inocchichichi/entrance/psqlodbc/;
> ?
>
> regards,
> Hiroshi Inoue
>
>
> On 2017/03/04 5:14, Jack C. Wei wrote:
>
> Hi,
>
> We have some legacy SQL queries that works on SQL Server but
> not on PostgreSQL due to SQL Server-specific syntax, which we
> are working to migrate. The problem is sometimes psqlodbc just
> cannot seem to reset itself after a bad query and simply go
> dead. All subsequent queries on the same connection,
> legitimate or not, would fail.
>
> I've verified this can happen with the latest PostgreSQL 9.6.2
> and psqlodbc 09_06_0100, on a Windows 7 x64 host.
>
> The offending SQL query is something like "UPDATE site SET
> image=image_old;" where [image] is BYTEA (used to be
> MEDIUMBLOB on SQL Server) and [image_old] is TEXT. PostgreSQL
> does not allow this, which is understandable. But after this
> query the connection goes dead, failing all subsequent queries
> with ODBC error 08S01 or HY000. While it is possible to detect
> this and reconnect as a workaround, it would be cumbersome and
> lead to unwarranted overhead. See the following excerpt from
> my ODBC trace log:
>
>
> PsqlOdbcBug f68-e10 EXIT SQLPrepareW with return code
> 0 (SQL_SUCCESS)
> HSTMT 0x00033EE8
> WCHAR * 0x010F0F28 [ -3] "UPDATE site
> SET image=image_old
>
>
> ;\ 0"
> SDWORD -3
>
> PsqlOdbcBug f68-e10 ENTER SQLExecute
> HSTMT 0x00033EE8
>
> PsqlOdbcBug f68-e10 EXIT SQLExecute with return code
> -1 (SQL_ERROR)
> HSTMT 0x00033EE8
>
> DIAG [42804] ERROR: column "image" is of type bytea
> but expression is of type text;
> Error while preparing parameters (1)
>
> PsqlOdbcBug f68-e10 ENTER SQLFreeHandle
> SQLSMALLINT 3 <SQL_HANDLE_STMT>
> SQLHANDLE 0x00033EE8
>
> PsqlOdbcBug f68-e10 EXIT SQLFreeHandle with return
> code 0 (SQL_SUCCESS)
> SQLSMALLINT 3 <SQL_HANDLE_STMT>
> SQLHANDLE 0x00033EE8
>
> PsqlOdbcBug f68-e10 ENTER SQLAllocHandle
> SQLSMALLINT 3 <SQL_HANDLE_STMT>
> SQLHANDLE 0x000338D8
> SQLHANDLE * 0x0035EB90
>
> PsqlOdbcBug f68-e10 EXIT SQLAllocHandle with return
> code 0 (SQL_SUCCESS)
> SQLSMALLINT 3 <SQL_HANDLE_STMT>
> SQLHANDLE 0x000338D8
> SQLHANDLE * 0x0035EB90 ( 0x00D51C98)
>
> PsqlOdbcBug f68-e10 ENTER SQLPrepareW
> HSTMT 0x00D51C98
> WCHAR * 0x010F0DE0 [ -3] "SELECT id
> FROM site;\ 0"
> SDWORD -3
>
> PsqlOdbcBug f68-e10 EXIT SQLPrepareW with return code
> 0 (SQL_SUCCESS)
> HSTMT 0x00D51C98
> WCHAR * 0x010F0DE0 [ -3] "SELECT id
> FROM site;\ 0"
> SDWORD -3
>
> PsqlOdbcBug f68-e10 ENTER SQLExecute
> HSTMT 0x00D51C98
>
> PsqlOdbcBug f68-e10 EXIT SQLExecute with return code
> -1 (SQL_ERROR)
> HSTMT 0x00D51C98
>
> DIAG [08S01] Could not send Query(connection dead);
> Could not send Query(connection dead) (26)
>
>
> I've attached a minimal working sample code (we develop in
> Visual Studio 2013) and also the ODBC trace log. Hopefully
> they make it through. Any feedback is welcome.
>
>
> Thank you,
> Jack Wei
>
>
>
^ permalink raw reply [nested|flat] 6+ messages in thread
end of thread, other threads:[~2017-03-08 10:53 UTC | newest]
Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2017-03-03 20:14 ODBC connections go dead after a failed query? Jack C. Wei <jackcwei+pgsql@gmail.com>
2017-03-03 20:27 ` Adrian Klaver <adrian.klaver@aklaver.com>
2017-03-03 21:53 ` Jack C. Wei <jackcwei+pgsql@gmail.com>
2017-03-04 13:48 ` Inoue, Hiroshi <h-inoue@dream.email.ne.jp>
2017-03-07 22:10 ` Jack C. Wei <jackcwei+pgsql@gmail.com>
2017-03-08 10:53 ` Inoue, Hiroshi <h-inoue@dream.email.ne.jp>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox