2014-01-29 51 views
0

我试图通过Microsoft Visual C++ 2010在HP-UX上连接到Informix。有关ODBC或其他连接到Informix的其他方法的帮助将不胜感激。使用Microsoft Visual C++连接到Informix

这是一个数据表单,需要从各种Informix表中查询,添加,更新和删除数据。

+0

欢迎来到Stack Overflow。请尽快阅读[关于]页面。这里肯定还有其他一些问题。有一个ODBC驱动程序可用于Windows(其中几个,实际上;选择最新的,应该从ClientSDK 4.10,AFAIK/CR)。也就是说,我不是一个Windows用户,更不用说Windows程序员,所以我没有更多的帮助。 –

+0

我应该补充说主要文档可以从[IBM Informix 12.10信息中心](http://pic.dhe.ibm.com/infocenter/informix/v121/index.jsp)获得。您还可以通过[Informix](http://www.informix.com/)获取信息,该信息可导向[IBM Informix Database Software](http://www-01.ibm.com/software/data/informix/) )。 –

回答

0

支持以下Informix驱动程序,并且可以使用包括VS2010的Visual Studio。 ODBC驱动程序。 .NET驱动程序。 OLE DB驱动程序。 ESQL/C

请让我知道你正在寻找什么具体信息。

+0

如果您有示例代码或有关连接/查询HP-UX计算机上的Informix的说明,这将有所帮助。我有Microsoft Visual C++ 2010 Win-32表单项目。 – Kevin

0
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. 

/////////////////////// ///// 这是一个非常简单的ODBC代码 //////////////////////////////////// ////////////

#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"); 
    } 
} 
1

在第一个客户机必须安装客户端。您可以从IBM网站下载它,其名称如下:clientsdk.3.70.TC5DE.WIN.zip。选择最新并安装它。使用setnet32(菜单启动/ IBM Informix Client SDK/setnet32)配置客户端。然后配置ODBC源。当被问及驱动程序使用“IBM Informix ODBC Driver”时。在“连接”选项卡上,您必须填写一些数据(主机,端口,数据库等)。您还会看到“应用&测试连接”按钮。用它。如果它有效,你可以开始编程。