[freetds] SQLPrepare returns SQL_ERROR but SQLError does not return anything

Roland Genske rhg at marxmeier.com
Fri Feb 29 05:40:09 EST 2008


Hello members of the FreeTDS mailing list,

this is my first post here although I am using FreeTDS for quite some
time already. So far all went well but now I encountered a weird problem.

The environment is FreeTDS 0.64 on Linux connecting to SQL Server 2005.
The ODBC driver manager is unixODBC.

This is an excerpt of an unixODBC trace of SQLPrepare returning SQL_ERROR:

[ODBC][23437][SQLPrepare.c][180]
    Entry:
      Statement = 0x80b3a50
      SQL = [INSERT INTO Products(Identifier,[Name],[Enable],IsOrderItem,UpdatedBy,LastUpdated,IsDeleted) VALUES (?,?,?,?,?,?,?)][length = 115]
[ODBC][23437][SQLPrepare.c][355]
    Exit:[SQL_ERROR]

Next, the application invokes SQLError on the statement:

[ODBC][23437][SQLError.c][342]
    Entry:
      Statement = 0x80b3a50
      SQLState = 0xbffff20c
      Native = 0xbffff104
      Message Text = 0xbffff10c
      Buffer Length = 256
      Text Len Ptr = 0xbffff10a
[ODBC][23437][SQLError.c][379]
    Exit:[SQL_NO_DATA]

As this returns SQL_NO_DATA it invokes SQLError again on
the connection:

[ODBC][23437][SQLError.c][424]
    Entry:
      Connection = 0x805bcd0
      SQLState = 0xbffff20c
      Native = 0xbffff104
      Message Text = 0xbffff10c
      Buffer Length = 256
      Text Len Ptr = 0xbffff10a
[ODBC][23437][SQLError.c][461]
    Exit:[SQL_NO_DATA]

Again SQL_NO_DATA, so try again on the environment:

[ODBC][23437][SQLError.c][504]
    Entry:
      Environment = 0x805b580
      SQLState = 0xbffff20c
      Native = 0xbffff104
      Message Text = 0xbffff10c
      Buffer Length = 256
      Text Len Ptr = 0xbffff10a
[ODBC][23437][SQLError.c][541]
    Exit:[SQL_NO_DATA]

Again SQL_NO_DATA, so there is no info on the cause of SQLPrepare
returning SQL_ERROR.

The passed handles are correct:

[ODBC][23437][SQLAllocHandle.c][345]
    Entry:
      Handle Type = 2
      Input Handle = 0x805b580
[ODBC][23437][SQLAllocHandle.c][463]
    Exit:[SQL_SUCCESS]
      Output Handle = 0x805bcd0

[ODBC][23437][SQLDriverConnect.c][666]
    Entry:
      Connection = 0x805bcd0
      Window Hdl = (nil)
      Str In = [DRIVER=FreeTDS;SERVER=SQL2005;UID=sa;PWD=*****;DATABASE=SenabIntegration;TDS_Version=8.0;Port=1433][length = 98 (SQL_NTS)]
      Str Out = 0xbfffea6c
      Str Out Max = 1024
      Str Out Ptr = 0xbfffea62
      Completion = 0
    UNICODE Using encoding ASCII 'ISO8859-1' and UNICODE 'UCS-2LE'

[ODBC][23437][SQLDriverConnect.c][1409]
    Exit:[SQL_SUCCESS]
      Connection Out [DRIVER=FreeTDS;SERVER=SQL2005;UID=sa;PWD=AEJ4p;DATABASE=SenabInt...]

I have no idea why SQLPrepare fails. The application is cross-platform
and works on the very same database on the very same server without any
problems when executed on Windows through the original MS SQL Server
ODBC driver.

There are quite a few statements successfully executed before this
problem occurs (no SQLPrepare however), for example:

[ODBC][23437][SQLAllocHandle.c][510]
    Entry:
      Handle Type = 3
      Input Handle = 0x805bcd0
[ODBC][23437][SQLAllocHandle.c][872]
    Exit:[SQL_SUCCESS]
      Output Handle = 0x80a1ad0

[ODBC][23437][SQLExecDirect.c][233]
    Entry:
      Statement = 0x80a1ad0
      SQL = [SELECT * FROM Customers WHERE   LastUpdated>'20080201 01:01'][length = 60]
[ODBC][23437][SQLExecDirect.c][496]
    Exit:[SQL_SUCCESS]

[ODBC][23437][SQLNumResultCols.c][149]
    Entry:
      Statement = 0x80a1ad0
      Column Count = 0xbfffedea
[ODBC][23437][SQLNumResultCols.c][234]
    Exit:[SQL_SUCCESS]
      Count = 0xbfffedea -> 20

I am not sure if it makes sense to post the entire trace file here (~3500
lines), but if this would be of any interest I will of course do that.

My hope is now that anybody here who reads this has a suggestion on how
I could continue to find out about why this happens and what to do to
solve this.

Thank you for any kind of help,
Roland



More information about the FreeTDS mailing list