开发者

Python - Linux - Connecting to MS SQL with Windows Credentials - FreeTDS+UnixODBC + pyodbc or pymssql

There doesn't seem to be any great instructions for setting this up. Does anyone have any good instructions? I am a linux noob so be gentle. I did see another post that is similar, but no real answer.

I have a couple of problems.

  1. FreeTDS doesn't "seem" to be working. I am trying to connect and I get the following message using the "tsql" command: "Default database being set to data开发者_StackOverflowbaseName There was a problem connecting to the server" but it doesn't mention what the problem is.

    1. The error I get when I try to connect using pyodbc is: "pyodbc.Error: ('08S01', '[08S01] [unixODBC][FreeTDS][SQL Server]Unable to connect: Adaptive Server is unavailable or does not exist (20009) (SQLDriverConnectW)')"

    2. I tried something similar with pymssql, but I ran into similar issues. I keep getting errors that I can't connect, but it doesn't tell me why.


The following works if you configure the MS SQL server to allow remote TCP/IP connections and have an appropriate user to connect as.

You also need to be careful to set up the correct hostname for the db as reported by MS SQL.

import pymssql
connection = pymssql.connect(
            user = 'username', 
            password = 'password', 
            host = 'server', 
            database = 'database',
        )
cursor = connection.cursor()
cursor.execute('select * from db;')
rows = cursor.fetchall()


When building FreeTDS (http://www.freetds.org/userguide/config.htm):

./configure --with-tdsver=8.0 --enable-msdblib


That error suggests that the TDS version is not set right. You can set that in the configuration setting for FreeTDS. You don't mention which MSSQL version you are using. But, if you are using say 2005, setting 8.0 as the TDS version will work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜