[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


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 :

        host =
        #port = 1433
        tds version = 8.0
        instance = SQLEXPRESS
        dump file = /tmp/tds-dump

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

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

#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
#Setup = Driver=/usr/lib/x86_64-linux-gnu/odbc/libtdsS.so
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 */
  /* 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,
                         outstr, sizeof(outstr), &outstrlen,
  if (SQL_SUCCEEDED(ret)) {
    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,
    SQLINTEGER   i = 0;
    SQLINTEGER   native;
    SQLCHAR      state[ 7 ];
    SQLCHAR      text[256];
    SQLRETURN    ret;

            "The driver reported the following diagnostics whilst running "

        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: