This discussion is archived
2 Replies Latest reply: Jan 2, 2013 10:47 PM by 981096 RSS

How to invoke the exported function of odbc32.dll

981096 Newbie
Currently Being Moderated
Hi,

I am unable to find the dll (SQLAllocHandle.dll) in our system. Its mentioned that the ‘SQLAllocHandle’ is one of the exported function of odbc32.dll

I want to find out how to invoke this exported function and make use of the same in our system?

Regards,
Jay
  • 1. Re: How to invoke the exported function of odbc32.dll
    gdarling - oracle Expert
    Currently Being Moderated
    Your question leads me to believe you're not sure what you're asking.

    SQLAllocHandle is an ODBC api call, and you use it in your ODBC API program, the same way you use other ODBC api calls.

    Here's an example of a simple ODBC API program that uses SQLAllocHandle.

    Hope it helps,
    Greg
     #include "windows.h"
    #include "stdio.h"
    #include "sql.h"
    #include "sqlext.h"
    
    void GetSQLError();
    #define checkforerrors if (rc!=SQL_SUCCESS){GetSQLError();exit(1);}
    
    static      HENV     henv;
    static      HDBC     hdbc;
    void main(int argc, char *argv[])
    {
         SQLRETURN rc=0;
         SQLCHAR* uid="SCOTT";
         SQLCHAR* pwd="tiger";
         SQLCHAR* dsn="orcl32";
         rc = SQLAllocHandle(SQL_HANDLE_ENV,SQL_NULL_HANDLE,&henv);checkforerrors
         rc = SQLSetEnvAttr(henv,  SQL_ATTR_ODBC_VERSION,(SQLPOINTER)SQL_OV_ODBC3,0);checkforerrors
         rc = SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc);checkforerrors
         rc = SQLConnect(hdbc, dsn, (SWORD)strlen(dsn), uid,(SWORD)strlen(uid),pwd,(SWORD)strlen(pwd));checkforerrors
         printf("connected\n");
         rc = SQLDisconnect(hdbc);checkforerrors
         rc = SQLFreeConnect(hdbc);checkforerrors
         rc = SQLFreeEnv(henv);checkforerrors
    }
    
    void GetSQLError()
    {
    long    llDbErrCd = 0;
    short   llRetMsgLen = 0;
    char    lszSqlErrMsg[255];
    char    lszSqlMsg[255];
    
    SQLError(henv,hdbc,0,(SQLCHAR*) lszSqlErrMsg,&llDbErrCd,(SQLCHAR*) lszSqlMsg,255,&llRetMsgLen);
    printf(lszSqlErrMsg);
    printf(lszSqlMsg);
    }
  • 2. Re: How to invoke the exported function of odbc32.dll
    981096 Newbie
    Currently Being Moderated
    Thanks Greg!

    In fact, I am new to ODBC concepts and I am using Windows Cobol to connect to 'SQL server' using ODBC. The below is the part of the Cobol code where it fails during run-time.

    ******************************************************************
    * ODBC3P.CPY *
    ----------------------------------------------------------------
    * Sample ODBC initialization, clean-up and error handling *
    * procedures (ODBC Ver 3.0) *
    ******************************************************************
    *** Initialization functions SECTION *****************************
    ODBC-Initialization SECTION.
    *
    Allocate-Environment-Handle.
    CALL "SQLAllocHandle" USING
    BY VALUE SQL-HANDLE-ENV
    BY VALUE SQL-NULL-HANDLE
    BY REFERENCE Henv
    RETURNING SQL-RC
    IF SQL-RC NOT = SQL-SUCCESS
    MOVE "SQLAllocHandle for Env" TO SQL-stmt
    MOVE SQL-HANDLE-ENV to DiagHandleType
    SET DiagHandle to Henv
    PERFORM SQLDiag-Function
    END-IF.
    *

    The error message I get while running the program is "IWZ096C Dynamic call of program SQLAllocHandle failed. The load module SQLAllocHandle.dll could not be found in the directories identified in the COBPATH environment variable".

    I have set up the ODBC connectivity correctly, but still getting the above error.

    Regards,
    Jay

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points