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