[erlang-questions] ODBC Connection Timeout

Ingela Anderton Andin <>
Fri Sep 21 16:24:35 CEST 2007


An idea:


--------- From the users Guide ---------------------

1.4 About the Erlang ODBC application

Provides an Erlang interface to communicate with relational
SQL-databases. It is built on top of Microsofts ODBC interface and
therefore requires that you have an ODBC driver to the database that
you want to connect to. The Erlang ODBC application is designed using
the version 3.0 of the ODBC-standard, however using the option
{scrollable_cursors, off} for a connection has been known to make it
work for at least some 2.X drivers.

-----------------------------------------------------

Regards  Ingela - OTP team


 > Hello ALL!
 >
 >I could not connect to mssql DB by erlang odbc module in Gentoo Linux.
 >After odbc:connect(...) I have got Error Report with Timeout Reason.
 >
 >The Steps that I've taken.
 >-Merged unixODBC Driver Manager  v2.2.12
 >-Merged the freetds ODBC driver with odbc and mssql USE flags. v0.64
 >-Merged erlang with hipo,java,kpoll,odbc,smp,ssl and tk USE flags v11.2.5
 >-Configured odbc.ini and odbcinst.ini  files.
 >
 >odbc.ini
 >
 >[ODBC Data Sources]
 >
 >MyDatabase = FREETDS SQLServer driver
 >MYSQLPL = My SQL
 >
 >
 >[MyDatabase]
 >Driver        = /usr/lib/libtdsodbc.so
 >Description    = SQL Server
 >Server        = ServerName\SQLEXPRESS
 >Port        = 1433
 >Language    =
 >Database    = PresenceLog
 >QuotedId    = No
 >AnsiNPW        = No
 >
 >
 >odbcins.ini
 >
 >[ODBC Drivers]
 >
 >FreeTDS = installed
 >
 >
 >[FreeTDS]
 >Description         = FreeTDS ODBC Driver
 >Driver                 = /usr/lib/libtdsodbc.so
 >Threading           = 0
 >FileUsage            = 1
 >DontDLClose     = 1
 >UsageCount        = 1
 >
 >
 >
 >Tested the connectivity to MSSQL database using  "isql". Everything works.
 >
 >Seted the enviroments ODBCINI and ODBCSYSINI
 >$ export ODBCINI=/etc/unixODBC/odbc.ini
 >$ export ODBCSYSINI=/etc/unixODBC/
 >
 >Try out sample.
 >
 > erl
 >         > application:start(odbc).
 >         > {ok, Ref} = odbc:connect("DSN=MyDatabase;UID=user;PWD=pwd", 
[]).
 >
 > Get as output:
 >
 >{error,connection_closed}
 >=ERROR REPORT==== 20-Sep-2007::14:16:58 ===
 >** Generic server <0.38.0> terminating
 >** Last message in was {<0.31.0>,
 >                        {connect,[1,
 >                                  1,
 >                                  2,
 >                                  1,
 >                                  1,
 >                                  "DSN=MyDatabase;UID=user;PWD=pwd"],
 >                                 on,
 >                                 on},
 >                        infinity}
 >** When Server state == {state,#Port<0.105>,
 >                               {<0.31.0>,#Ref<0.0.0.68>},
 >                               <0.31.0>,
 >                               undefined,
 >                               on,
 >                               undefined,
 >                               undefined,
 >                               on,
 >                               connecting,
 >                               undefined,
 >                               0,
 >                               [#Port<0.103>,#Port<0.104>],
 >                               undefined,
 >                               undefined}
 >** Reason for termination ==
 >** timeout
 >
 >
 >I tried the DSN again via two little c program.
 >
 >DSN LIST:
 >
 >
 >#include <stdio.h>
 >#include <sql.h>
 >#include <sqlext.h>
 >
 >main() {
 >  SQLHENV env;
 >  char dsn[256];
 >  char desc[256];
 >  SQLSMALLINT dsn_ret;
 >  SQLSMALLINT desc_ret;
 >  SQLUSMALLINT direction;
 >  SQLRETURN ret;
 >
 >  SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &env);
 >  SQLSetEnvAttr(env, SQL_ATTR_ODBC_VERSION, (void *) SQL_OV_ODBC3, 0);
 >
 >  direction = SQL_FETCH_FIRST;
 >  while(SQL_SUCCEEDED(ret = SQLDataSources(env, direction,
 >                       dsn, sizeof(dsn), &dsn_ret,
 >                       desc, sizeof(desc), &desc_ret))) {
 >    direction = SQL_FETCH_NEXT;
 >    printf("%s - %s\n", dsn, desc);
 >    if (ret == SQL_SUCCESS_WITH_INFO) printf("\tdata truncation\n");
 >  }
 >}
 >
 >It founds both of my DSNs.
 >
 >Connection TEST by *Edmund Dengler*
 >
 >> #include <stdio.h>
 >> #include <stdlib.h>
 >> #include <string.h>
 >> #include <sql.h>
 >> #include <sqlext.h>
 >> #include <pthread.h>
 >
 >#define MAX_CONN_STR_OUT 1024
 >#define TIME_OUT 10
 >
 >int main() {
 >  unsigned char *connStrIn = "DSN=MyDatabase;UID=user;PWD=pwd";
 >  SQLCHAR connStrOut[MAX_CONN_STR_OUT];
 >  SQLRETURN stringlength2ptr, result;
 >  SQLSMALLINT connlen;
 >
 >  SQLHENV env;
 >  SQLHDBC connect;
 >
 >  SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &env);
 >  SQLSetEnvAttr(env, SQL_ATTR_ODBC_VERSION, (SQLPOINTER)SQL_OV_ODBC3, 0);
 >
 >  SQLAllocHandle(SQL_HANDLE_DBC, env, &connect);
 >  SQLSetConnectAttr(connect, SQL_ATTR_CONNECTION_TIMEOUT,
 >(SQLPOINTER)TIME_OUT, 0);
 >  SQLSetConnectAttr(connect, SQL_ATTR_AUTOCOMMIT,
 >(SQLPOINTER)SQL_AUTOCOMMIT_ON, 0);
 >  SQLSetConnectAttr(connect, SQL_ATTR_TRACE,
 >(SQLPOINTER)SQL_OPT_TRACE_OFF, 0);
 >
 >  connlen = (SQLSMALLINT)strlen((const char*)connStrIn);
 >
 >  printf("Connecting\n");
 >  result = SQLDriverConnect(connect, NULL,
 >                            (SQLCHAR *)connStrIn,
 >                            connlen,
 >                            connStrOut, (SQLSMALLINT)MAX_CONN_STR_OUT,
 >                            &stringlength2ptr, SQL_DRIVER_NOPROMPT);
 >  printf("Done (%d)\n", result);
 >}
 >
 >The result was SQL_SUCCESS
 >
 >
 >If anybody has any ideas, they would be greatly appreciated!




More information about the erlang-questions mailing list