Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2003
    Posts
    223

    Unanswered: How to query SQL Server on windows from LINUX?

    Hello, everyone:

    I have a C++ codes on Linux and SQL Server 2005 Express on Windows. C++ codes need to query data from SQL Server. How to setup then connection? Any suggestion will be great appreciated.

    ZYT
    ZYT

  2. #2
    Join Date
    May 2005
    Location
    South Africa
    Posts
    1,365
    Provided Answers: 1

  3. #3
    Join Date
    Apr 2008
    Posts
    1

    Mr.

    Dear pdreyer,

    I have the same problem to connect MS SQL server express from Linux.

    I download a FreeTDS ODBC Driver, built it and installed.

    Following is my code

    #include "sqlext.h"
    #define MAX_OUT_CONNECTION_STRING_LEN 1024

    SQLHDBC connection;
    unsigned char outConnectionString[MAX_OUT_CONNECTION_STRING_LEN];
    SQLSMALLINT len;
    SQLHSTMT cmd;
    SQLRETURN ret;
    SQLHENV context;

    ret = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &context);

    ret = SQLAllocHandle(SQL_HANDLE_DBC, context, &connection);

    ret = SQLAllocHandle(SQL_HANDLE_STMT, connection, &cmd);

    ret = SQLDriverConnect(connection, NULL, (SQLCHAR *)
    "DRIVER=FreeTDS;SERVER=SQLEXPRESS;UID=sa;PWD=test; APP=name of my executable file;WSID=IP of My SQL machine;Port=1433", SQL_NTS, outConnectionString,MAX_OUT_CONNECTION_STRING_LEN, &len,
    SQL_DRIVER_NOPROMPT);

    The first three ret are 0 but the last one is -1.
    Your suggestions are great appreciated.

  4. #4
    Join Date
    Apr 2008
    Posts
    29
    I've never done it with C++, but i've done some RADIUS server implementation and needed both freeTDS and unixODBC to connect successfully to the SQL Server....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •