0

I'm trying to connect from ubuntu (kubuntu 13.04) with nodejs to a sql server db! (sql server 2012) I was looking at node odbc.. so.. I start installing FreeTds, then unixOdbc, then launch: npm install odbc

1) I configured the file "etc/freetds/freetds.conf" like this:

[FreeTDS]
host = gerry_win7
port = 1433
tds_version = 8.0
client charset = UTF-8

2) install sqsh (sudo apt-get install sqsh) and try to connect with

sqsh -S FreeTDS -U trm1 -P user

and execute a query: works perfectly!

3) then, I tried to configure ODBC access in this way: file "/etc/odbcinst.ini":

[FreeTDS]
Description = TDS driver
Driver = /usr/lib/i386-linux-gnu/odbc/libtdsodbc.so
Setup = /usr/lib/i386-linux-gnu/odbc/libtdsS.so
CPTimeout =
CPReuse =
FileUsage = 1

file "/etc/odbc.ini":

[FreeTDS]
Driver = FreeTDS
Description = ODBC connectin via FreeTDS
Trace = No
Servername = gerry_win7
Database = testsql
UID = trm1
PWD = user
Port = 1433

4) with this sample code with nodejs I received the following error: code:

var cn = 'DRIVER={FreeTDS};SERVER=gerry_win7;UID=trm1;PWD=user;DATABASE=testsql';
var Database = require('odbc').Database, db = new Database();
db.open(cn, function(err){
    if (err) {return console.log(err);}
});

error:

[unixODBC][FreeTDS][SQL Server]Unable to connect to data source
[Error: Error opening database]

but, as I wrote before, with the "sqsh" client the connection works: I can run queries! can someone help me understand what I'm doing wrong?

3
  • Most likely not the problem, but shouldn't tds_version be tds version with a space? Commented Mar 31, 2014 at 19:17
  • You may also want to try SERVERNAME instead of SERVER in the connection string. Commented Mar 31, 2014 at 19:24
  • yes sorry.. "tds version".. I was wrong to write in the post but in the configuration file was correct.. I tried to write SERVERNAME but the error is the same.. Commented Mar 31, 2014 at 19:57

1 Answer 1

0

This is the connection string I would use if I were specifying the DRIVER in it:

"DRIVER={FreeTDS};SERVERNAME=gerry_win7;DATABASE=testsql;UID=trm1;PWD=user;AutoTranslate=yes"

If you want to use the DSN that you have configured in /etc/odbc.ini then you would want to do:

"DSN=FreeTDS;UID=trm1;PWD=user;DATABASE=testsql"

Testing with the sqsh command may just use the configuration information that is in /etc/freetds/freetds.conf (citation needed). It is best to test your ODBC configuration (outside of node) with the isql command like:

$ isql FreeTDS trm1 user

Where FreeTDS is the DSN configured in /etc/odbc.ini.

Your configuration may be a little bit confusing because both the driver name and the DSN name are FreeTDS. I personally find it more helpful to use the server name or some other identifier as the DSN name specified in /etc/odbc.ini. I would suggest something like this in your odbc.ini:

[gerry]
Driver = FreeTDS
Description = ODBC connectin via FreeTDS
Trace = No
Servername = gerry_win7
Database = testsql
UID = trm1
PWD = user
Port = 1433

Then use this connection string:

"DSN=gerry;UID=trm1;PWD=user;DATABASE=testsql"

Doing it that way, you could potentially just change the Driver entry in the odbc.ini file if you want to use the SQL Server Native Client 11.0, if you get to that point. :)

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you very much!!... just one thing: in the odbc.ini configuration the parameter is not "Servername" but "Server" (with Servername doesn't work I see.. I found a wrong example)..
Glad it worked for you. Interesting about the "Servername" parameter. That's what I use in my odbc.ini and it works. As long as you got yours working, that's all that matters. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.