无法使用 soci 库连接到 SQL 服务器

Unable to connet to SQL server using soci library

本文关键字:连接 SQL 服务器 soci      更新时间:2023-10-16

我是 c++ 的初学者,我在 Linux 上使用 soci 库连接到 SQL Server 的问题,我的代码这个,但我有错误,我没有找到我的问题的解决方案,我的代码是这样的:

我有错误:

[unixODBC][Driver Manager]Data source name not found, and no default driver specified (SQL state IM002)

这是代码:

try{
      soci::session sql("odbc","DSN=ODBC;UID=sa;PWD=sa123; Connection Driver=TDS;Database=ReportServer; Server=192.168.1.52;Port=1433;");
    }
    catch(soci::odbc_soci_error const & e){
        cout<<"start error";
        cout<<e.odbc_error_code()<<endl;
        cout<<e.what();            
    }

ODBC 连接字符串不正确,第一个参数指定名为"ODBC"的数据源,该数据源尚未在操作系统/ODBC 管理器中配置。

因此,您应该使用给定的参数(如UID=sa;PWD=sa123; Connection Driver=TDS;Database=ReportServer; Server=192.168.1.52;Port=1433;相应的 ODBC 数据源管理器/linux 管理程序)配置数据源,使用可用名称(如"local_test_db"),并且仅使用"DSN=local_test_db"作为连接字符串

(独占或)

从连接字符串中删除"dsn=ODBC"部分,然后使用"UID=sa;PWD=sa123;连接驱动程序 = TDS;数据库 = 报表服务器;服务器=192.168.1.52;端口=1433;"