2012-12-23 45 views
2

我想将我的C++客户端连接到PostgreSQL数据库。我不断收到otlv4.h | 12406 |未定义的引用'SQLFreeHandle @ 8'以及其他许多未定义的引用错误。尝试使用OTL连接到我的PostgreSQL服务器

要获得头文件去http://otl.sourceforge.net/otl3_down.htm

#include <iostream> 

using namespace std; 

#include <stdio.h> 
#include <string.h> 
#include <stdlib.h> 
// #define OTL_ODBC_UNIX // uncomment this line if UnixODBC is used 
#define OTL_ODBC_ALTERNATE_RPC 
#if !defined(_WIN32) && !defined(_WIN64) 
#define OTL_ODBC 
#else 
#define OTL_ODBC_POSTGRESQL // required with PG ODBC on Windows 
#endif 
#include "otlv4.h" // include the OTL 4.0 header file 

otl_connect db; // connect object 

int main() 
{ 

    otl_connect::otl_initialize(); // initialize ODBC environment 

    db.rlogon("postgres/[email protected]"); 

    db.commit(); 

    cout << "Hello world!" << endl; 

    db.logoff(); // disconnect from ODBC 
    return 0; 
} 
+0

您是否安装了[PgODBC] [1]? [1]:http://www.postgresql.org/ftp/odbc/versions/msi/ – mvp

+0

PostgreSQL35W虽然 –

+0

是的,我有它安装 –

回答

0

当我使用ODBC没有从Windows到PostgreSQL的连接,我用DSN的方法。它需要从用户角度进行零输入 - 用户不需要知道ODBC是什么以及如何配置ODBC源(DSN)。

使用DSN-less连接的典型方式是使用字符串像下面为您的ODBC连接字符串:

Driver=PostgreSQL;Server=hostname;Database=mypgdb;UID=username;PWD=password 

注意,驱动程序名称可能需要根据版本和ANSI VS Unicode的口味进行调整。

相关问题