我正在尝试通过Microsoft Visual C++ 2010在HP-UX上连接到Informix。任何有关ODBC或其他连接到Informix的方式的帮助都将不胜感激。
它是一种数据表单,需要从各种Informix表中查询、添加、更新和删除数据。
发布于 2014-01-30 18:43:17
首先,您必须在客户机上安装客户端。您可以从IBM下载它,它的名称类似于:clientsdk.3.70.TC5DE.WIN.zip
。选择最新版本并安装它。使用setnet32
配置客户机(菜单Start/IBM Informix client SDK/setnet32)。然后配置ODBC源。当询问驱动程序时,使用"IBM Informix ODBC Driver“。在Connection选项卡上,您必须填写一些数据(主机、端口、数据库等)。您还将看到“应用和测试连接”按钮。使用它。如果它工作正常,你可以开始编程了。
发布于 2014-01-30 01:25:09
支持以下Informix驱动程序,并且可以在Visual Studio中使用它,包括VS2010。ODBC驱动程序。.NET驱动程序。OLE DB驱动程序。ESQL/C
请让我知道您正在寻找的具体信息。
发布于 2014-01-30 03:45:17
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");
}
}
https://stackoverflow.com/questions/21437867
复制相似问题