ODBC SQL connect problem - Mailing list pgsql-odbc

From ggorcsos
Subject ODBC SQL connect problem
Date
Msg-id 200209250729.JAA02661@www4.pobox.sk
Whole thread Raw
List pgsql-odbc
Dear Sir!
I have installed Linux Mandrake 8.3 and I have problem with the
connection to postgresDB via ODBC.
I configured .odbc.ini file and used the query_db.c source for DB
Connestion test.
The application was compiled this way:
gcc -lpsqlodbc -I/usr/include/pgsql query_db.c -o query_db

I tried the ODBCtest SW and as you can see bellow the connection was
established.

When I have executed the querry_db there has been a problem.
connection paarmeters: DSN='RHDB', UID='postgres', PWD=''
Unable to open data source (ret=-1)

Could you help me, please?
Tank you.
Gabor Gorcsos


/****************** ODBCtest ******************/
SQLAllocEnv():
  In:
    phenv: 0xbfffe1fc
  Return:
    SQL_SUCCESS=0
    *phenv: 0x81abf58

SQLAllocConnect():
  In:
    Environment Handle: 0x81abf58
    phdbc: 0xbfffe1fc
  Return:
    SQL_SUCCESS=0
    *phdbc: 0x81b1ef8

SQLConnect():
  In:
    Connection Handle: 0x81b1ef8
    Server: RHDB
    Server Len: SQL_NTS=-3
    User: postgres
    User Len: SQL_NTS=-3
    Auth: <null ptr>
    Auth Len: SQL_NTS=-3
  Return:
    SQL_SUCCESS=0
/*********************************************/


/***************** .odbc.ini *******************/
[ODBC Data Sources]
RHDB = PostgreSQL Test

[RHDB]
Driver=/usr/lib/libpsqlodbc.so
Description=Sample PostgreSQL DSN
DSN=RHDB
Servername=localhost
Username=postgres
Database=basketball
ReadOnly=No
Servertype=postgres
Port=5432
FetchBufferSize=99
ServerOptions=
ConnectOptions=
Options=
ReadOnly=no
Trace=1
TraceFile=/home/ggorcsos/odbc.trace
Debug=1
DebugFile=/home/ggorcsos/odbc.debug
CommLog=1

[Default]
Driver = /usr/lib/libpsqlodbc.so

[ODBC]
InstallDir = /usr/lib/libodbc.so
/*************************************/



/**************************************** query_db.c
************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <sqlext.h>

HENV Environment;
HDBC Connection;
HSTMT Statement;

static unsigned char SelectStmt[] = {"SELECT 'Connected to:
ENG='||property('name')||', DBN='||db_property('name')"};
int main( int argc, char * argv[] )
{
    int res;
    unsigned char * connect_name = (unsigned char *)"RHDB";
    unsigned char * connect_userid = (unsigned char *)"ggorcsos";
    unsigned char * connect_password = (unsigned char *)"";
    SQLCHAR cname[256];
    SQLINTEGER cnamesize;


    if( SQLAllocEnv( &Environment ) != SQL_SUCCESS )
    {
        printf( "Unable to allocate env\n" );
        exit( 0 );
    }

    if( SQLAllocConnect( Environment, &Connection ) !=
SQL_SUCCESS )
    {
        printf( "Unable to allocate connection\n" );
        SQLFreeEnv( Environment );
        exit( 0 );
    }

    if( argc > 1 )
    {
        connect_name = (unsigned char *)argv[1];
        if( argc > 2 )
        {
            connect_userid = (unsigned char *)argv[2];
            if( argc > 3 )
            {
                connect_password = (unsigned char *)
argv[3];
            }
        }
    }


    printf( "connection parameters: DSN='%s', UID='%s', PWD='%
s'\n", connect_name, connect_userid, connect_password);

    res = SQLConnect( Connection, connect_name, SQL_NTS,
connect_userid, SQL_NTS, connect_password, SQL_NTS );
    if( res != SQL_SUCCESS )
    {
        printf( "Unable to open data source (ret=%d)\n",
res );
        exit( 0 );
    }

    if( SQLAllocStmt( Connection, &Statement ) != SQL_SUCCESS )
    {
        printf( "Unable to allocate statement\n" );
        exit( 0 );
    }

    if( SQLExecDirect( Statement, SelectStmt, SQL_NTS )    !=
SQL_SUCCESS )
    {
        printf( "Unable to execute statement\n" );
        exit( 0 );
    }

    res = SQLFetch(Statement);
    if( res != SQL_SUCCESS && res != SQL_SUCCESS_WITH_INFO )
    {
        printf( "Unable to fetch row\n" );
        exit( 0 );
    }

    if( SQLGetData(Statement, 1, SQL_C_CHAR, cname, 255,
&cnamesize) != SQL_SUCCESS)
    {
        printf( "Unable to get data\n" );
        exit( 0 );
    }

    printf( "%s\n", cname );
    SQLDisconnect( Connection );
    SQLFreeConnect( Connection );
    SQLFreeEnv( Environment );
    printf( "Done.\n" );
    return( 0 );
}
/*********************************************************************
******************************/


____________________________________
http://www.pobox.sk/ - najvacsi slovensky freemail




pgsql-odbc by date:

Previous
From: Hiroshi Inoue
Date:
Subject: Re: Delphi / ODBC / DataSet.RecordCount failed on 7.2.2
Next
From: Peter Staudt
Date:
Subject: Text-Varchar Truncation via ODBC