Luc Ettlinger
Luc Ettlinger

Reputation: 71

FreeTDS - TSQL fails when password given in option, but succeeds when typed?

I'm trying to connect to a MS SQL Server trough PHP 5.6 with an Ubuntu 16.04 server. I'm forced to use this version of PHP, in order to assure compatibility with an 'ancient' application.

I installed PHP 5.6 and its modules (pdo, pdo_mysql, readline, etc.) trough ondrej's PPA without any trouble, but I wasn't able to find and install the 'mssql.so' module package needed for the application I'm trying to make work.

That's why I decided I would use ODBC (and PDO_ODBC) drivers in order to connect to the database.

In order to do so, I installed freetds with unixodbc and configured my files like this :

'odbcinst.ini' file :

enter image description here

'odbc.ini' file :

enter image description here

and finally the 'freetds.conf' file :

enter image description here

Ok, I guess all my files are well configured, but the next part starts to be a bit weird, let me explain you : when I try to connect to the MS SQL database using tsql and not giving the password in option but typing it when asked, the connexion works :

enter image description here

But when I try to give the same password as an option (-P), it doesn't work (I tried it at least 10 times with the correct password) !!!

enter image description here --> tsql failed to open a session for the user 'WIPSOS-PHP'

The same problem happens when I try to use isql with one of my connectors I configured in the 'odbc.ini' file :

enter image description here

It seems to be related to the password, but I can't find the problem, can you please help me ?

Upvotes: 4

Views: 1160

Answers (1)

Luc Ettlinger
Luc Ettlinger

Reputation: 71

I found a partial answer, and it was effectively related to the password: it seems like special characters are not well interpreted when present in the password given for the -P option of the tsql command.

Therefore, depending on you shell, you have to escape these characters in the string which completes an option. In my case, using bash, I had to use the '\' to escape the special character :

tsql -S hostname -D Database -U User -P pa\$\$word

And it now works!

enter image description here

But when I try to escape the special characters with '\' in the 'odbc.ini' file, it still doesn't seem to work :

enter image description here

My next question is : 'How to escape a special character in a '.ini' file ?' or 'Is there something wrong in my configuration ?'

EDIT: I know it was a long time ago, but I had a configuration problem related to the hostname in the "freetds.conf" file. In fact, I was using the server's local network DNS name instead of its IP adress(which works).

I hope my issue will at least help some people, it isn't easy to deal with TSQL and FreeTDS...

Upvotes: 1

Related Questions