13

I need to write some data to SQL Server database from Linux in C++.

I found this sqlapi.com

But I think, at first ODBC driver has to be installed and has to work.

I folowed this adminlife.net/allgemein/mssql-zugriff-unter-debian-etch-mit-unixodbc-und-freetds/ or this http://b.gil.megiteam.pl/2009/11/linux-odbc-to-mssql/

But it didn't work. The port 1433 seems to be closed ($ sudo nmap -PN -sU -p 1433 192.168.56.101 -> port "filtered")

isql -v sqlexpress sa -> wait with no response or get "couldn't connect to sql"

From other PC with Windows I have no problem to write data in SQL Server, so server should be right configured to remote access.

Any ideas?

Tom H
  • 46,766
  • 14
  • 87
  • 128
Meloun
  • 13,601
  • 17
  • 64
  • 93

2 Answers2

8

Here are the links I bookmarked concerning that topic, hope it can help you:

It was some time ago, but basically what I remember is:

You have to create an entry for the particular MSSQL driver you have in a file named /etc/odbcinst.ini. Then, for each MSSQL server, you have to create an entry (or DSN), either globaly in /etc/odbc.ini, or user-local, in $HOME/.odbc.ini.

Some names I used might differ (and I don't have acces to my Linux box right now to check) but you got the general idea.

Once you did that, isql -d should connect succesfully to the database. If so, then using the C/Linux API for ODBC should be a piece of cake. Tutorials provided in the given links.

ereOn
  • 53,676
  • 39
  • 161
  • 238
  • Oh and I remember that some tweaking has to be done on the MSSQL Server itself. You must allow TCP connections and access using login/password. – ereOn Mar 30 '10 at 14:25
4

FreeTDS is what you want. "FreeTDS is a set of libraries for Unix and Linux that allows your programs to natively talk to Microsoft SQL Server and Sybase databases."

http://www.freetds.org

Joe
  • 41,484
  • 20
  • 104
  • 125
  • nothing new for me, didnt help, i made all of this, there is the same procedure in links I have posted.. – Meloun Mar 30 '10 at 20:15
  • If you can't find port 1433 open on the SQL server box, then you have a problem unrelated to the libraries you're using. – Joe Mar 30 '10 at 20:44
  • 1
    But 'www.freetds.org' is not. Fixed. – Joe Feb 27 '15 at 22:02