Skip to Content.
Sympa Menu

freetds - [freetds] SQLPrepare() can't arrange error infomation when DB shutdown occured after SQLConnect()

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: "seong hoon park" <seonghoon AT gmail.com>
  • To: freetds AT lists.ibiblio.org
  • Subject: [freetds] SQLPrepare() can't arrange error infomation when DB shutdown occured after SQLConnect()
  • Date: Wed, 7 Jun 2006 17:39:54 +0900

Hello~
I'm tring to build a system with

- sqlrelay ver. 0.37
- unixODBC ver. 2.2.11
- FreeTDS ver. 0.63

I had been sufferd from some problem.
It was that SQLError() couldn't get correct error message after
SQLPrepare() failed
and the error message returned by SQLError() was not valid null-terminated
string.

Finding a thread about same situation (
http://lists.ibiblio.org/pipermail/freetds/2005q3/018897.html) ,
the problem was mostly fixed by applying attached patch file .

Unfortunately It seems not to be perfectly fixed.
If SQLConnect() had succeeded and client lost the connection to the SQL
server (shutdown maybe) after that
then following SQLPrepare() failed but it could not arrange detailed error
informations which will be retrieved by SQLError().

sqlrelay call SQLConnect() once and use SQLPrepare() repeatedly.
It also retry to connect to the DBMS when connection is lost.
so detecting lost connection is important to sqlrelay .

In constrat to SQLPrepare() , SQLExecDirect() might be able to catch error
correctly.

For convenience , I reproduced it using PHP.

In PHP , odbc_do() call SQLExecDirect() and odbc_prepare() use SQLPrepare().

do.php use odbc_do() and prepare.php use odbc_prepare().

both scripts do sleep() after odbc_connect() and DBMS is shutted down before
they are awakened

$php prepare.php
----------------
state = 00000
msg = A@暉@H?월?
/tmp/php-5.0.5/ext/odbc/php_odbc.c(849) : Freeing 0x0834F984 (36 bytes),
script=prepare.php
=== Total 1 memory leaks detected ===


$ php do.php
----------------
state = 08S01
msg = [unixODBC][FreeTDS][SQL Server]Write to SQL Server failed.


---contents of prepare.php---
$conn = odbc_connect('FreeTDS','sqlr','sqlr');
$query = 'select 1;';
sleep (10) ;
# shutdown database
$s = @odbc_prepare($conn,$query); # odbc_do in do.php
echo "----------------\n";
if($e=odbc_error())
{
echo "state = $e\n";
echo "msg = ".odbc_errormsg($conn)."\n";
}
----------------------------------------

I could find the patch file mentioned above in the mailing list archive .
It might be more convenient if patch files reside with source tarballs at
FTP site.

Thanks in advance.
I really appreciate the effort of developers.


  • [freetds] SQLPrepare() can't arrange error infomation when DB shutdown occured after SQLConnect(), seong hoon park, 06/07/2006

Archive powered by MHonArc 2.6.24.

Top of Page