【问题标题】:Unable to connet to SQL server using soci library无法使用 soci 库连接到 SQL Server
【发布时间】:2018-12-27 14:07:43
【问题描述】:

我是 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();            
    }

【问题讨论】:

    标签: c++ sql-server linux odbc soci


    【解决方案1】:

    您的 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; Connection Driver=TDS;Database=ReportServer; Server=192.168.1.52;Port=1433;”重试/p>

    【讨论】:

    • 谢谢,我会试试的
    猜你喜欢
    • 2020-02-11
    • 2016-03-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多