Este é um exemplo mínimo, mas completo, de como conectar-se ao Banco de Dados SQL do Azure com isql
do Ubuntu 14.04.1 LTS O exemplo é extraído de Como conectar o banco de dados SQL do Azure ao Ubuntu (disclaimer: é o meu wiki pessoal).
Instalar os pacotes necessários
$ sudo apt-get -y install freetds-bin tdsodbc unixodbc
Configurar o FreeTDS
Arquivo /etc/freetds/freetds.conf
[global]
tds version = 7.1
[<SERVERNAME>]
host = <HOST>.database.windows.net
port = 1433
Conexão de teste
Neste ponto, conectar-se a tsql
deve funcionar:
$ tsql -S <SERVERNAME> -U <USERNAME>@<HOST> -P <PASSWORD>
Observe que @<HOST>
é obrigatório. Caso contrário, a conexão termina com um erro:
Msg 40531 (severity 11, state 1) from [<SERVERNAME>] Line 1:
"Server name cannot be determined. It must appear as the first segment of the server's dns name (servername.database.windows.net). Some libraries do not send the server name, in which case the server name must be included as part of the user name (username@servername). In addition, if both formats are used, the server names must match."
Error 20002 (severity 9):
Adaptive Server connection failed
There was a problem connecting to the server
Configurar o driver ODBC
Arquivo /etc/odbcinst.ini
[FreeTDS]
Description = FreeTDS Driver
Driver = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
Configurar as fontes de dados ODBC
Arquivo /etc/odbc.ini
[<DATA_SOURCE_NAME>]
Driver = FreeTDS
Servername = <SERVERNAME>
Port = 1433
Database = <DBNAME>
<SERVERNAME>
é o mesmo que em freetds.conf
.
Conecte-se ao isql
$ isql -v <DATA_SOURCE_NAME> <USER>@<HOST> <PASSWORD>
+---------------------------------------+
| Connected! |
| |
| sql-statement |
| help [tablename] |
| quit |
| |
+---------------------------------------+
SQL> select current_timestamp
+------------------------+
| |
+------------------------+
| 2015-01-02 09:05:55.593|
+------------------------+
SQLRowCount returns 1
1 rows fetched
SQL>
Observe que @<HOST>
é obrigatório. Caso contrário, a conexão termina com um erro:
[S1000][unixODBC][FreeTDS][SQL Server]Unable to connect to data source
[37000][unixODBC][FreeTDS][SQL Server]Server name cannot be determined. It must appear as the first segment of the server's dns name (servername.database.windows.net). Some libraries do not send the server name, in which case the server name must be included as part of the user name (username@servername). In addition, if both formats are used, the server names must match.
[ISQL]ERROR: Could not SQLConnect