1.How to enable freetds dump
$TDSDUMP=/tmp/freetds.log tsql -H mysql_sqlserver -p 1433 -U sa
2.這一版的unixodbc可能有問題,在網路上看到有人提到,一定等手動把odbcinist.ini存放在/etc下面才有作用,
所以我用了sybolic link去幾絕這個問題,也成功的建立連線
$create sybolic to /etc from /usr/local/etc/odbcinst.ini
3.sample code
##/usr/bin/python
import sqlalchemy as sa import urllib URI='DRIVER={FreeTDS};Server=%s;Database=db_ControlManager;UID=%s;PWD=%s;TDS_Version=8.0;Port=1433;' % (server,user,password) connection_string='mssql+pyodbc:///?odbc_connect='+urllib.quote_plus(URI) engine = sa.create_engine(connection_string) conn=engine.connect() conn=db_connect() sql="select * from tb_userinfo" result=conn.execute(sql).fetchall() for row in result: for col in row: print col
沒有留言:
張貼留言