[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

How to connect to SQL Server using ODBC and still have kde on my machine



Hi,

I'm used to use freetds + tdsodbc to connect to SQL Servre from debian.
I noticed that if I install tdsodbc kde is beign uninstalled:

Maintainer: Steve Langasek <vorlon@debian.org>
Architecture: amd64
Replaces: freetds0, libct0, libct1
Depends: libc6 (>= 2.3), odbcinst1debian2 (>= 2.2.11-3), debconf (>=
0.5) | debconf-2.0, freetds-common
Recommends: libodbc1 | libiodbc2
Conflicts: freetds0, libct0, unixodbc (<< 2.1.1-2)
Breaks: libiodbc2, odbcinst1debian2 (<< 2.2.14p2-3), unixodbc (<< 2.2.14p2-3)

looking in the bts I see it is deliberate
(http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=639817) .

anyhow I need to connect to SQL Server (2005 and up) and need to be
able to do that using some odbc connection (the DSN can be in an ini
but best is to avoid that for me).

in freetds I need to set up driver  (that tdsodbc provides).

any ideas how can I do that without breaking kde ?

config  files :
freetds.conf:

.
.
.
[sql2008]
        host = 192.168.1.2
        #port = 1433
        tds version = 8.0
        instance = SQLEXPRESS
        dump file = /tmp/tds-dump

odbc$ cat /etc/odbc.ini
[sql2008]
Driver = FreeTDS
Trace = Yes
Servername = sql2008
Database   = master
TraceFile = /tmp/unixodbc.trace


odbc$ cat /etc/odbcinst.ini
[ODBC]
Trace        = Yes
TraceFile    = /tmp/sql.log
ForceTrace   = Yes

[FreeTDS]
#you can see I was searching for a single driver that could work (none
excpet tds worked)
#so I built the package on my machine and didn't install it . but this
is a bad idea
Driver=/opt/wasteoftime/freetds-0.82/debian/tmp/usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
#Driver=/usr/lib/x86_64-linux-gnu/libct.so.4.0.0
#Driver=/usr/lib/x86_64-linux-gnu/libodbcinst.so.1.0.0
#Driver=/usr/lib/x86_64-linux-gnu/libsybdb.so.5.0.0
#Setup = Driver=/usr/lib/x86_64-linux-gnu/odbc/libtdsS.so
UsageCount=1
FileUsage=1
tds version=8.0

code example from unixodbc :
//compile by gcc filename.c -o filename -lodbc
#include <stdio.h>
#include <sql.h>
#include <sqlext.h>

/*
 * see Retrieving ODBC Diagnostics
 * for a definition of extract_error().
 */
static void extract_error(
    char *fn,
    SQLHANDLE handle,
    SQLSMALLINT type);

main() {
  SQLHENV env;
  SQLHDBC dbc;
  SQLHSTMT stmt;
  SQLRETURN ret; /* ODBC API return status */
  SQLCHAR outstr[1024];
  SQLSMALLINT outstrlen;

  /* Allocate an environment handle */
  SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &env);
  /* We want ODBC 3 support */
  SQLSetEnvAttr(env, SQL_ATTR_ODBC_VERSION, (void *) SQL_OV_ODBC3, 0);
  /* Allocate a connection handle */
  SQLAllocHandle(SQL_HANDLE_DBC, env, &dbc);
  /* Connect to the DSN mydsn */
  ret = SQLDriverConnect(dbc, NULL,
"Driver=FreeTds;SERVER=192.168.1.2\\SQLEXPRESS;UID=test;PWD=pwd;DATABASE=master",
SQL_NTS,
                         outstr, sizeof(outstr), &outstrlen,
                         SQL_DRIVER_COMPLETE);
  if (SQL_SUCCEEDED(ret)) {
    printf("Connected\n");
    printf("Returned connection string was:\n\t%s\n", outstr);
    if (ret == SQL_SUCCESS_WITH_INFO) {
      printf("Driver reported the following diagnostics\n");
      extract_error("SQLDriverConnect", dbc, SQL_HANDLE_DBC);
    }
    SQLDisconnect(dbc);         /* disconnect from driver */
  } else {
    fprintf(stderr, "Failed to connect\n");
    extract_error("SQLDriverConnect", dbc, SQL_HANDLE_DBC);
  }
  /* free up allocated handles */
  SQLFreeHandle(SQL_HANDLE_DBC, dbc);
  SQLFreeHandle(SQL_HANDLE_ENV, env);
}

void extract_error(
    char *fn,
    SQLHANDLE handle,
    SQLSMALLINT type)
{
    SQLINTEGER   i = 0;
    SQLINTEGER   native;
    SQLCHAR      state[ 7 ];
    SQLCHAR      text[256];
    SQLSMALLINT  len;
    SQLRETURN    ret;

    fprintf(stderr,
            "\n"
            "The driver reported the following diagnostics whilst running "
            "%s\n\n",
            fn);

    do
    {
        ret = SQLGetDiagRec(type, handle, ++i, state, &native, text,
                            sizeof(text), &len );
        if (SQL_SUCCEEDED(ret))
            printf("%s:%ld:%ld:%s\n", state, i, native, text);
    }
    while( ret == SQL_SUCCESS );
}

using Debian sid AMD64.


Reply to: