Re: MS SQL Server 2000 ODBC driver crash

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Jason Hinsperger (NOJason_HinspergerSPAM_at_hotmail.com)
Date: 03/08/04


Date: Mon, 8 Mar 2004 11:15:42 -0500

I retract my previous statement. It turns out that if I create the tables
as part of my test program, the crash still remains.
Here is an updated test program to demonstrate the problem. The only
difference from the original one I posted is that the program now
drops/creates the table used in the select statement.
I don't think I have a coding problem here, but you never know. Can you
take a look again?

Thanks very much,

Jason Hinsperger
iAnywhere Solutions

#include <stdio.h>

#include <stdlib.h>

#include <f:\work\issues\raymondwang\odbc.h>

#include <string.h>

#if ODBCVER < 0x0350

#error "***** This module requires ODBC 3.5 or higher *****"

#endif

typedef struct ml_host_data {

SQLHENV env;

} ml_host_data, *p_ml_host_data;

typedef struct ml_host_conn {

p_ml_host_data host;

SQLHDBC dbc;

} ml_host_conn, *p_ml_host_conn;

p_ml_host_data Init( void )

/*************************/

{

p_ml_host_data host;

RETCODE ret;

host = (p_ml_host_data) malloc( sizeof( *host ) );

if( host != NULL ) {

ret = SQLAllocHandle( SQL_HANDLE_ENV, SQL_NULL_HANDLE, &host->env );

ret = SQLSetEnvAttr( host->env,

SQL_ATTR_ODBC_VERSION,

(SQLPOINTER)SQL_OV_ODBC3,

0 );

}

return( host );

}

void Fini( p_ml_host_data host )

/******************************/

{

RETCODE ret;

// Clean up any resources and shut the module down.

if( host->env != SQL_NULL_HENV ) {

ret = SQLFreeHandle( SQL_HANDLE_ENV, host->env );

}

}

p_ml_host_conn Connect(

/**********************/

p_ml_host_data host,

char * conn_str )

{

// Establish a connection with the host database. This may

// create a new connection or just grab one from a pool

// of connections.

p_ml_host_conn conn;

SQLSMALLINT conn_str_len;

char out_str[ 2048 ];

RETCODE ret = SQL_ERROR;

conn = (p_ml_host_conn) malloc( sizeof( ml_host_conn ) );

if( conn == NULL ) {

goto done;

}

conn->host = host;

conn->dbc = SQL_NULL_HDBC;

ret = SQLAllocHandle( SQL_HANDLE_DBC, host->env, &conn->dbc );

ret = SQLDriverConnect( conn->dbc,

NULL, // HWND_NULL,

(SQLCHAR *)conn_str,

SQL_NTS,

(SQLCHAR *)out_str,

sizeof( out_str ),

&conn_str_len,

SQL_DRIVER_NOPROMPT );

if( ret == 0 ) printf( "Connection succeed\n" );

// Establish connection options

// Use transactions instead of auto-commit

ret = SQLSetConnectAttr( conn->dbc,

SQL_ATTR_AUTOCOMMIT,

(SQLPOINTER)SQL_AUTOCOMMIT_OFF,

SQL_IS_UINTEGER );

if( ret == 0 ) printf( "Set Connection succeed\n" );

done:

return( conn );

}

void Disconnect( p_ml_host_conn conn )

/************************************/

{

if( conn != NULL ) {

if( conn->dbc != SQL_NULL_HDBC ) {

SQLDisconnect( conn->dbc );

SQLFreeHandle( SQL_HANDLE_DBC, conn->dbc );

}

free( conn );

}

}

void ShowBug( p_ml_host_conn conn )

/*********************************/

{

SQLHSTMT stmt;

RETCODE ret;

int id;

SQLINTEGER ind1=0, ind2=0;

SQLWCHAR source[1001];

ret = SQLAllocHandle( SQL_HANDLE_STMT, conn->dbc, &stmt );

ret = SQLPrepare( stmt,

(SQLCHAR *)"select id, source from ssint2", SQL_NTS );

ret = SQLExecute( stmt );

ret = SQLBindCol( stmt, 1, SQL_C_SLONG, &id, 4, &ind1 );

ret = SQLBindCol( stmt, 2, SQL_C_WCHAR, source, sizeof( source), &ind2);

ret = SQLFetchScroll( stmt, SQL_FETCH_NEXT, 0 );

while( ret != SQL_NO_DATA_FOUND ) {

ret = SQLFetchScroll( stmt, SQL_FETCH_NEXT, 0 );

}

ret = SQLFreeHandle( SQL_HANDLE_STMT, stmt );

ret = SQLEndTran( SQL_HANDLE_DBC, conn->dbc, SQL_ROLLBACK );

}

void Setup( p_ml_host_conn conn )

{

SQLHSTMT stmt;

RETCODE ret;

//Drop table

ret = SQLAllocHandle( SQL_HANDLE_STMT, conn->dbc, &stmt );

ret = SQLPrepare( stmt, (SQLCHAR *)"drop table ssint2", SQL_NTS );

ret = SQLExecute( stmt );

ret = SQLFreeHandle( SQL_HANDLE_STMT, stmt );

//Create table ssint,

ret = SQLAllocHandle( SQL_HANDLE_STMT, conn->dbc, &stmt );

ret = SQLPrepare( stmt, (SQLCHAR *)"create table ssint2( id INT not null
primary key, source char(1000) NULL)", SQL_NTS );

ret = SQLExecute( stmt );

ret = SQLFreeHandle( SQL_HANDLE_STMT, stmt );

ret = SQLAllocHandle( SQL_HANDLE_STMT, conn->dbc, &stmt );

ret = SQLPrepare( stmt, (SQLCHAR *)"INSERT INTO ssint2 values( 1, 'S1' )",
SQL_NTS );

ret = SQLExecute( stmt );

ret = SQLFreeHandle( SQL_HANDLE_STMT, stmt );

ret = SQLEndTran( SQL_HANDLE_DBC, conn->dbc, SQL_COMMIT );

}

int _tmain( int argc, char *argv[] )

/********************************/

{

p_ml_host_data host = NULL;

p_ml_host_conn conn = NULL;

host = Init();

if( host != NULL ) {

argc = argc; // Unused

conn = Connect( host, argv[ 1 ] );

Setup( conn );

if( conn != NULL ) {

// ===========================

ShowBug( conn );

// ===========================

Disconnect( conn );

}

Fini( host );

}

return( 0 );

}

"Jason Hinsperger" <NOJason_HinspergerSPAM@hotmail.com> wrote in message
news:uUpx2WvAEHA.628@TK2MSFTNGP10.phx.gbl...
> Thanks for the information. I was using the latest odbc driver, but you
> suggestion made me think to check the server. Applying SP 3 resovles the
> problem.
>
> Thanks again,
>
> --
> Jason Hinsperger
> International and Sustaining Engineering
> iAnywhere Solutions
>
> Whitepapers, TechDocs, and bug fixes are all available through the
iAnywhere
> Developer Community at www.ianywhere.com/developer
> --
>
>
> "Tian Min Huang" <timhuang@online.microsoft.com> wrote in message
> news:pLMAgPdAEHA.2304@cpmsftngxa06.phx.gbl...
> > Hello,
> >
> > Thanks for your post. As I understand, the problem you are facing is
that
> > SQLFreeHandle crashes to free the statement handle.
> >
> > I performed the steps as described in your post, however, I am not able
to
> > reproduce the problem on my side. I think more information is needed
> before
> > moving forward:
> >
> > 1. Did you apply any SQL Server service pack? What's the version?
> >
> > 2. On my test system, the SQL Server ODBC Drver version is
> 2000.85.1025.00,
> > you can upgrade yours by applying the latest MDAC version at:
> >
>
http://msdn.microsoft.com/data/downloads/updates/default.aspx#MDACDownloads.
> >
> > 3. Please also check the call stack when it crashes.
> >
> > I am standing by for your response.
> >
> > Have a nice day!
> >
> > Regards,
> >
> > HuangTM
> > Microsoft Online Partner Support
> > MCSE/MCSD
> >
> > Get Secure! -- www.microsoft.com/security
> > This posting is provided "as is" with no warranties and confers no
rights.
> >
>
>



Relevant Pages