试图使用OTL连接到我的PostgreSQL服务器

Trying to use OTL to connect to my PostgreSQL server

本文关键字:我的 PostgreSQL 服务器 连接 OTL      更新时间:2023-10-16

我正在尝试连接我的c++客户端到PostgreSQL数据库。我一直得到otlv4.h|12406|对' SQLFreeHandle@8'的未定义引用和许多其他未定义引用错误。

要获取头文件请访问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/changeme@numbers");
    db.commit();
    cout << "Hello world!" << endl;
    db.logoff(); // disconnect from ODBC
    return 0;
}

当我使用ODBC从Windows连接到PostgreSQL时,我使用了较少的dsn方法。从用户的角度来看,它不需要任何输入——用户不需要知道什么是ODBC以及如何配置ODBC源(DSN)。

使用无dns连接的典型方法是使用如下字符串作为您的ODBC连接字符串:

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

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