2016-09-08 11 views
0

私はCentOSの上だと私は、以下のものを使用して、私のデータベースにログインすることができますunixODBCとFreeTDSを使用してAzureに接続するにはどうすればいいですか?

TDSVER=7.2 tsql -H example.database.windows.net -U myname -D MyDataBase -p 1433 

は、その後、私は自分のパスワードを入れて、私は-OKにログインすることができます。残念ながらisql/osqlは同じことをやるのがはるかに難しいようです。

〜/ .odbc.iniをisqlを使用して

[AwesomeDatabase] 
Description = Azure Awesome Database 
Trace = off 
Server = example.database.windows.net 
Database = AwesomeDatabase 
UID = [email protected] 
PWD = mypassword 
Port = 1433 
TDS Version = 7.2 
ForceTrace  = off 
Encrypt   = yes 
#Driver   = FreeTDS 
Driver   = /usr/lib64/libtdsodbc.so 
Ansi   = True 
client charset = utf-8 

⚘ isql -v CDH 
[S1000][unixODBC][FreeTDS][SQL Server]Unable to connect to data source 
[01000][unixODBC][FreeTDS][SQL Server]Unexpected EOF from the server 
[01000][unixODBC][FreeTDS][SQL Server]Adaptive Server connection failed 
[ISQL]ERROR: Could not SQLConnect 

まあ、それは残念だ

私の設定は次のようになります。 osqlをしよう:

⚘ osql -S AwesomeDatabase -U [email protected] -P mypassword # I've tried wayne instead of [email protected], neither works 
checking shared odbc libraries linked to isql for default directories... 
strings: '': No such file 
     trying /tmp/sql ... no 
     trying /tmp/sql ... no 
     trying /etc ... OK 
checking odbc.ini files 
     reading /home/me/.odbc.ini 
[AwesomeDatabase] found in /home/me/.odbc.ini 
found this section: 
     [AwesomeDatabase] 
     Description = Azure Awesome Database 
     Trace = off 
     Server = example.database.windows.net 
     Database = AwesomeDatabase 
     UID = [email protected] 
     PWD = mypassword 
     Port = 1433 
     TDS Version = 7.2 
     ForceTrace  = off 
     Encrypt   = yes 
     #Driver   = FreeTDS 
     Driver   = /usr/lib64/libtdsodbc.so 
     Ansi   = True 
     client charset = utf-8 
looking for driver for DSN [AwesomeDatabase] in /home/me/.odbc.ini 
    found driver line: " Driver   = /usr/lib64/libtdsodbc.so" 
    driver "/usr/lib64/libtdsodbc.so" found for [AwesomeDatabase] in .odbc.ini 
found driver named "/usr/lib64/libtdsodbc.so" 
/usr/lib64/libtdsodbc.so is an executable file 
"Server" found, not using freetds.conf 
Server is "example.database.windows.net" 

Configuration looks OK. Connection details: 

        DSN: AwesomeDatabase 
       odbc.ini: /home/me/.odbc.ini 
       Driver: /usr/lib64/libtdsodbc.so 
     Server hostname: example.database.windows.net 
       Address: 191.235.192.43 

Attempting connection as wayne ... 
+ isql CDH wayne mypassword -v 
[S1000][unixODBC][FreeTDS][SQL Server]Unable to connect to data source 
[01000][unixODBC][FreeTDS][SQL Server]Unexpected EOF from the server 
[01000][unixODBC][FreeTDS][SQL Server]Adaptive Server connection failed 
[ISQL]ERROR: Could not SQLConnect 
net.c:202:FAILED Connecting to 191.235.192.43 port 1433 (TDS version 4.2) 

私はLinux上でのunixODBCを使用してのAzureに接続するために行うには何が必要ですか?

答えて

0

ユーザー名とパスワードを入力しないと、信頼できる接続として扱われるという問題があります。私はそれが意味するものは100%ではありませんが、明らかに動作しません。作業用の設定は実際はかなり簡単です。 (対話的にそれを取得する方法があるかどうかわからないがあり、常にxargsます。)

[AwesomeDatabase] 
Description = Azure Awesome Database 
Server = example.database.windows.net 
Database = AwesomeDatabase 
Port = 1433 
# Note the underscore 
TDS_Version = 7.2 
# Or `FreeTDS if you want to put some settings in your 
# odbcinst.ini file 
Driver   = /usr/lib64/libtdsodbc.so 

は今、あなたは ISQLのコマンドラインでパスワードを提供する必要があります。

$ isql AwesomeDatabase [email protected] mypassword # "wayne" without @example seems to work, too. 

そして、それだけで動作します良い。あなたはSQLAlchemyのを使用している場合は、そのようpyodbcを経由して接続することができます。

import sqlalchemy 
from urllib.parse import quote 

engine = sa.create_engine(
    'mssql+pyodbc://{user}:{password}@AwesomeDatabase'.format(
     user=quote('[email protected]'), 
     password=quote('mypassword'), 
    ), 
    legacy_schema_aliasing=False, 
) 

for row in engine.execute(sa.text('select current_timestamp')): 
    print(*row) 

または、ストレートpyodbcを使用して:

import pyodbc 

# Without the Uid/Pwd it thinks it's a Trusted Connection 
# again 
conn = pyodbc.connect('DSN=AwesomeDatabase;[email protected];Pwd=mypassword;') 
cursor = conn.cursor() 
cursor.execute('select current_timestamp'); 
for row in cursor.fetchall(): 
    print(*row) 

そして人生今、あなたのために幸せになるはずです。

関連する問題