Python - Linux - 使用 Windows 凭据连接到 MS SQL - FreeTDS+UnixODBC + pyodbc 或 pymssql

发布于 2024-09-02 13:45:05 字数 609 浏览 5 评论 0 原文

似乎没有任何关于设置此功能的详细说明。有人有什么好的指示吗?我是一个 Linux 菜鸟,所以要温柔。我确实看到了另一篇文章 类似,但没有真正的答案。

我有几个问题。

  1. FreeTDS“似乎”不起作用。我正在尝试连接,并使用“tsql”命令收到以下消息:“默认数据库设置为databaseName 连接到服务器时出现问题”,但没有提及问题是什么。

  2. 尝试使用 pyodbc 连接时出现的错误是:“pyodbc.Error: ('08S01', '[08S01] [unixODBC][FreeTDS][SQL Server]无法连接: Adaptive Server is不可用或不存在 (20009) (SQLDriverConnectW)')"

  3. 我尝试使用 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 databaseName
    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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

格子衫的從容 2024-09-09 13:45:05

如果您将 MS SQL Server 配置为允许远程 TCP/IP 连接并拥有适当的用户进行连接,则以下操作有效。

您还需要小心地为 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()

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()
所谓喜欢 2024-09-09 13:45:05

构建 FreeTDS 时 (http://www.freetds.org/userguide/config.htm ):

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

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

./configure --with-tdsver=8.0 --enable-msdblib
尘曦 2024-09-09 13:45:05

该错误表明 TDS 版本设置不正确。您可以在 FreeTDS 的配置设置中进行设置。您没有提及您正在使用哪个 MSSQL 版本。但是,如果您使用的是 2005 年,则将 TDS 版本设置为 8.0 即可。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文