Search code examples
phpazurepdoazure-sql-databasefreetds

Can't connect to Azure SQL with FreeTDS


I've been scouring the web for 6 hours now and still haven't managed to figure this out. If you have a duplicate question link, I'm all-ears, but I've probably seen it already :/

I'm trying to connect to my Azure SQL instance via my LAMP stack and it's just not happening and I'm not sure why.

I've compiled and installed FreeTDS with openssl, installed php5-sybase, unixodbc, tdsodbc, php5-odbc, etc, etc

FreeTDS namelookups are working, but actual connection to the server isn't working. I'm getting the very generic 20009 Adaptive Server is unavailable error.

I've added my IP to the allowed IP list in the Azure portal as well. I've tried TDS versions 7.0, 7.1, 7.2, and 7.3 as well as each permutation of those with encryption = off|request|require.

I've tried connecting to the freeTDS name, the DNS name, and the direct IP address. I've tried specifying the port as well as leaving it off. I've verified there are no local firewalls.

This is what I see with tsql (and with PHP, the same eventual error as well):

locale is "en_US.UTF-8"
locale charset is "UTF-8"
using default charset "UTF-8"
Setting MyDatabase as default database in login packet
14> Error 20009 (severity 9):
    Unable to connect: Adaptive Server is unavailable or does not exist
There was a problem connecting to the server

Here is my freetds.conf:

[BlueRavenSolar]
    host = myserver.database.windows.net
    port = 1443
    tds version = 7.3
    encryption = request

And the output of tsql -C:

Compile-time settings (established with the "configure" script)
                        Version: freetds v0.95.89
         freetds.conf directory: /usr/local/etc
 MS db-lib source compatibility: yes
    Sybase binary compatibility: no
                  Thread safety: yes
                  iconv library: yes
                    TDS version: 5.0
                          iODBC: no
                       unixodbc: no
          SSPI "trusted" logins: no
                       Kerberos: no
                        OpenSSL: yes
                         GnuTLS: no

Solution

  • Have you changed the port of Azure SQL, as the port in your freetds.conf is 1443, and the default port of Azure SQL should be 1433. So can you try to modify to 1433 and try again?