Skip to content
Advertisement

Unable to connet to SQL server using soci library

I am beginner in c++,my problem on Linux for connecting to SQL Server with soci library, my code this but I have error and I don’t found solution for my problem, my code this:

I have error:

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

Here is the code:

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

Advertisement

Answer

Your ODBC connection string in incorrect, your first parameter specifies a datasource called “ODBC”, which you haven’t configured in your operating system/odbc manager.

So either you should configure a data source with the given parameters like UID=sa;PWD=sa123; Connection Driver=TDS;Database=ReportServer; Server=192.168.1.52;Port=1433; with the corresponding ODBC data source manager/linux administration program, with a useable name like “local_test_db” and just use “DSN=local_test_db” as your connection string

or (exclusive or)

remove the “dsn=ODBC” part from your connection string and try it again with “UID=sa;PWD=sa123; Connection Driver=TDS;Database=ReportServer; Server=192.168.1.52;Port=1433;”

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement