Pyodbc:登录超时错误 [英] Pyodbc: Login Timeout Error

查看:65
本文介绍了Pyodbc:登录超时错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 pyodbc 从运行 Ubuntu 16.04 的远程机器连接到 MS SQL Server.

I am trying to connect to MS SQL Server using pyodbc from a remote machine running Ubuntu 16.04.

import pyodbc 

conn = pyodbc.connect(r'DRIVER=ODBC Driver 17 for SQL Server; SERVER=xxxTest-SRV; PORT=51333; DATABASE=TestDB; UID=xxxx; PWD=xxxx;')

我收到以下错误:

pyodbc.OperationalError: ('HYT00', '[HYT00] [unixODBC][Microsoft][ODBC驱动程序 17 for SQL Server]登录超时已过期 (0)(SQLDriverConnect)')

pyodbc.OperationalError: ('HYT00', '[HYT00] [unixODBC][Microsoft][ODBC Driver 17 for SQL Server]Login timeout expired (0) (SQLDriverConnect)')

我尝试在连接字符串中使用服务器 IP 但仍然没有运气.

I tried using the server IP in the connection string but still no luck.

但是,我可以从终端使用 sqlcmd 进行连接
以下作品:

However, I am able to connect to using sqlcmd from the terminal
Following works:

sqlcmd -S xxxTest-SRV, 51333 -d TestDB -U xxxx -P xxxx

我没有找到任何可以解决我的问题的问题.

I didn't find any issue that gave an answer to my problem.

odbcinst.ini

[ODBC Driver 17 for SQL Server]
Description=Microsoft ODBC Driver 17 for SQL Server
Driver=/opt/microsoft/msodbcsql/lib64/libmsodbcsql-17.1.so.1.1
UsageCount=1

使用 pyodbc 从 Linux 机器连接到 MS SQL Server 似乎总是出现问题.有没有办法从 Python 连接到 SQL Server.感谢您帮助解决此错误.谢谢你.

There's always seems to be an issue connecting to MS SQL Server using pyodbc from a linux machine. Is there a way to connect to SQL Server from Python. I'll appreciate your help in solving this error. Thank you.

[更新]

根据以下答案,我更新了连接字符串.但是,现在我收到以下错误:

As per the below answer, I updated the connection string. But, now I get following error:

pyodbc.Error: ('01000', "[01000] [unixODBC][Driver Manager]无法打开lib'/opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.0.so.1.1':文件未找到 (0) (SQLDriverConnect)")

pyodbc.Error: ('01000', "[01000] [unixODBC][Driver Manager]Can't open lib '/opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.0.so.1.1' : file not found (0) (SQLDriverConnect)")

我的odbcinst.ini文件驱动定义:

My odbcinst.ini file driver definition:

[ODBC Driver 17 for SQL Server]
Description=Microsoft ODBC Driver 17 for SQL Server
Driver=/opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.0.so.1.1
UsageCount=1

从 Linux 机器连接到 MS SQL Server 一直是一场噩梦.请问pyodbcunixODBCDriver哪个版本最稳定?

It has always been a nightmare to connect to MS SQL Server from a Linux machine. Can you please tell which pyodbc, unixODBC and Driver version is the most stable?

我已经按照 this Microsoft 说明.我的 pyodbc 版本是 4.0.23

I have installed the driver following this Microsoft instructions. My pyodbc version is 4.0.23

推荐答案

Microsoft 的 SQL Server ODBC 驱动程序不使用 PORT= 参数.端口号(如果有)用逗号附加到服务器名称/IP,例如,

Microsoft's ODBC drivers for SQL Server do not use a PORT= parameter. The port number, if any, is appended to the server name/IP with a comma, e.g.,

SERVER=xxxTest-SRV,51333;

这篇关于Pyodbc:登录超时错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆