Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cjtnA-0008PH-6v for pgsql-odbc@arkaria.postgresql.org; Fri, 03 Mar 2017 20:27:08 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1cjtn9-0001nq-Df for pgsql-odbc@arkaria.postgresql.org; Fri, 03 Mar 2017 20:27:07 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1cjtn8-0001kv-SY for pgsql-odbc@postgresql.org; Fri, 03 Mar 2017 20:27:07 +0000 Received: from out4-smtp.messagingengine.com ([66.111.4.28]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1cjtn6-0004oQ-5I for pgsql-odbc@postgresql.org; Fri, 03 Mar 2017 20:27:05 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id EF861206EB; Fri, 3 Mar 2017 15:27:02 -0500 (EST) Received: from frontend1 ([10.202.2.160]) by compute6.internal (MEProxy); Fri, 03 Mar 2017 15:27:02 -0500 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=aklaver.com; h= content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc:x-sasl-enc; s=mesmtp; bh=6b0Tby70Zilp6wW 9yvLwL3YBqhs=; b=iQqglo+N85GiuEUYgvT9r9uAPms/ERdvXKaJODBNOuUqzbs pBwVxfOA9dbxkrmF04I60TD3AOxkKqeR2PqZT3jbRra4mE5V/lnIMa0eFL6b8tLP 0nAJUQA7DB9sdXTnfa94RKDWFBV49+RlBsgR2tRGvkbE2eUsq/QvJfSg7PSs= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc:x-sasl-enc; s= smtpout; bh=6b0Tby70Zilp6wW9yvLwL3YBqhs=; b=nhVdkd6em+i+BmKv+6db r/Xi2lJbvq5JQvSvfBqgkK/U6MecFNWbtGZUyebbte64HVYAkZwPyCvD4Tpb735+ 6VcMzh/4dCXGzAm4eMwX74ggOOFOtwe1ghGMHRZMURU9fimP/TvbiK5c8q9tzg7y URNI/TY4mu1cccsSacB99GQ= X-ME-Sender: X-Sasl-enc: 3nGoT+LaDXtl8PUjY4KQLvK9HMhvftn2yXLBHNCXNSen 1488572822 Received: from [192.168.1.2] (174-21-203-58.tukw.qwest.net [174.21.203.58]) by mail.messagingengine.com (Postfix) with ESMTPA id 7870F7E077; Fri, 3 Mar 2017 15:27:02 -0500 (EST) Subject: Re: ODBC connections go dead after a failed query? To: "Jack C. Wei" , pgsql-odbc@postgresql.org References: From: Adrian Klaver Message-ID: Date: Fri, 3 Mar 2017 12:27:01 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -2.7 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-odbc Precedence: bulk Sender: pgsql-odbc-owner@postgresql.org 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 > SQLHANDLE 0x00033EE8 > > PsqlOdbcBug f68-e10 EXIT SQLFreeHandle with return code 0 > (SQL_SUCCESS) > SQLSMALLINT 3 > SQLHANDLE 0x00033EE8 > > PsqlOdbcBug f68-e10 ENTER SQLAllocHandle > SQLSMALLINT 3 > SQLHANDLE 0x000338D8 > SQLHANDLE * 0x0035EB90 > > PsqlOdbcBug f68-e10 EXIT SQLAllocHandle with return code 0 > (SQL_SUCCESS) > SQLSMALLINT 3 > 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