Visual c++ 如果您有关于连接/查询HP-UX机器上的Informix的示例代码或说明,这将有所帮助。我有微软Visual C++ 2010 Win 32表单项目。 The .NET driver has the most trivial setup among the

Visual c++ 如果您有关于连接/查询HP-UX机器上的Informix的示例代码或说明,这将有所帮助。我有微软Visual C++ 2010 Win 32表单项目。 The .NET driver has the most trivial setup among the,visual-c++,odbc,informix,Visual C++,Odbc,Informix,如果您有关于连接/查询HP-UX机器上的Informix的示例代码或说明,这将有所帮助。我有微软Visual C++ 2010 Win 32表单项目。 The .NET driver has the most trivial setup among these drivers. Assuming you have already done client server connectivity setup on your system by using SetNet32. Then you ma


如果您有关于连接/查询HP-UX机器上的Informix的示例代码或说明,这将有所帮助。我有微软Visual C++ 2010 Win 32表单项目。
The .NET driver has the most trivial setup among these drivers.
Assuming you have already done client server connectivity setup on your system by using SetNet32.

Then you may need to add reference to the .net provider binary (IBM.Data.Informix.dll) to your VS project, that is all needed as part of setup.
This binary is located at bin\netf<.net framework version>

For example:C:\CSDK\bin\netf40\

A sample connection string: "Database=MyDb1;UID=myuser;PWD=MyPassword;Server=MyServerInst";


    If you are using C/C++ application then ODBC driver may be a better choice.
    These are the two most common usages of ODBC driver.
    Using ODBC driver directly
    Using ODBC driver through a driver manager.

    Here is the instruction to use Informix ODBC driver directly.
    (If you want to use by using driver manager then change the include and library accordingly from the instruction).

    1) Create VS 2010 C++ Console Application Project
    File -> New Project
    Visual C++
    Win32 Console Application.
    Create an Empty Project 
    <Give Project Name>
    <Press OK>
    <Application Option Check Mark 'Empty Project'>
    <Press Finish Button>

    2) Setup Informix ODBC driver reference to the project
{

    From the Solution Explorer Right Click on the Project Name
    From the pop-up menu that appear, select Property
    From the dialog box do the following setting. 

    Configuration Properties :
    General
    Select appropriate value for 'Character Set'
    If you are not using Unicode API then make sure you have selected 
    Use Multi Byte Character Set


    C/C++:
    General 
    Additional Include Directories
    (Give the include directory location)
    C:\CSDK\incl\cli

    Linker
    General
    Additional Library Directories
    (Give the LIB directory location)
    C:\CSDK\lib

    Linker:
    Command Line
    Additional Options
    (Specify the Informix ODBC driver library)
    iclit09b.lib
}

Your project is ready to use Informix ODBC driver to connect any Informix Dynamic Servers.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

//#ifdef WIN32 || WIN64
#ifdef WIN32
#include <io.h>
#include <windows.h>
#include <conio.h>
#endif

#ifdef USE_DRIVER_MANAGER
#include "sql.h"
#include "sqlext.h"
#else
#include <infxcli.h>
#endif

void GetDiagRec(SQLRETURN rc, SQLSMALLINT htype, SQLHANDLE hndl, char *szFunTag );

int main( int argc, char *argv[] )
{
    SQLHENV         henv=NULL;
    SQLHDBC         hdbc=NULL;
    SQLRETURN       rc = 0;

    SQLCHAR         ConnStrIn[1024]=
        "DRIVER={IBM INFORMIX ODBC DRIVER};SERVER=MyServerInst;DATABASE=MyDatabase;HOST=HpHost.ibm.com;PROTOCOL=onsoctcp;SERVICE=5550;UID=MyUser;PWD=PasswordForMyUser;";

    rc = SQLAllocHandle( SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv );
    rc = SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION, (void*)SQL_OV_ODBC3,0);
    rc = SQLAllocHandle( SQL_HANDLE_DBC, henv, &hdbc );

    printf( "\n ConnStr=[%s]\n", ConnStrIn);

    rc = SQLDriverConnect( hdbc, NULL, ConnStrIn, SQL_NTS, NULL, 0, NULL, SQL_DRIVER_NOPROMPT );
    if (rc != SQL_SUCCESS)
    {
        GetDiagRec(rc, SQL_HANDLE_DBC, hdbc, "SQLDriverConnect" );
        exit(1);
    }

    // Do Some Work Here
     printf( "\n Connection Success! \n", ConnStrIn);

    rc = SQLDisconnect(hdbc);
    rc = SQLFreeHandle(SQL_HANDLE_DBC,hdbc);
    rc = SQLFreeHandle(SQL_HANDLE_ENV,henv);

    return(0);
}



void GetDiagRec(SQLRETURN rc, SQLSMALLINT htype, SQLHANDLE hndl, char *szFunTag )
{ 
    SQLCHAR message[SQL_MAX_MESSAGE_LENGTH + 1];
    SQLCHAR sqlstate[SQL_SQLSTATE_SIZE + 1];
    SQLINTEGER sqlcode;
    SQLSMALLINT length;

    if ( szFunTag == NULL )
    {
        szFunTag = "---";
    }

    printf  ( "\n %s: %d : ", szFunTag, rc);

    if (rc >= 0)
    {
       printf  ( " OK [rc=%d]", rc);
    }
    else
    {  
        int i=1;

        printf  ( " FAILED: %i", rc);
       //Get diagnostic record
       while (SQLGetDiagRec(htype,
                            hndl,
                            i,
                            sqlstate,
                            &sqlcode,
                            message,
                            SQL_MAX_MESSAGE_LENGTH + 1,
                            &length) == SQL_SUCCESS)
       {
         printf  ( "\n SQLSTATE          = %s", sqlstate);

         printf( "\n Native Error Code = %ld", sqlcode);

         printf  ( "\n %s", message);
         i++;
       }
       printf  ( "\n-------------------------\n");
    }
}