我正在尝试在我本地计算机上运行的Docker容器中连接到MSSQL的实例。我使用了Microsoft的这组指令来设置容器,并且容器中的所有内容似乎都按预期运行:
https://learn.microsoft.com/en-us/sql/linux/quickstart-install-install-connect-docker?view=sql-sql-server-ver16&pivots = cs1-bash
我正在尝试使用Python从我的本地计算机(不在容器中)连接数据库。我已经尝试了各种迭代,但是连接脚本通常是:
import pyodbc
server = 'localhost,1433'
database = 'TestDB'
username = 'sa'
password = '<YourStrong@Passw0rd>'
cnxn = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};SERVER='+server+';DATABASE='+database+';UID='+username+';PWD='+ password)
cursor = cnxn.cursor()
生成PYODBC错误:
pyodbc.OperationalError: ('HYT00', '[HYT00] [Microsoft][ODBC Driver 17 for SQL Server]Login timeout expired (0) (SQLDriverConnect)')
我检查了驱动程序是正确的
mssql@sql1:/$ cat /etc/odbcinst.ini
[ODBC Driver 17 for SQL Server]
Description=Microsoft ODBC Driver 17 for SQL Server
Driver=/opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.9.so.1.1
UsageCount=1
,并检查了端口是否打开。
谁能帮助如何使该连接起作用?
I'm trying to connect to an instance of MSSQL in a Docker container that is running on my local machine. I used this set of instructions from Microsoft to set up the container, and everything within the container seems to be functioning as expected:
https://learn.microsoft.com/en-us/sql/linux/quickstart-install-connect-docker?view=sql-server-ver16&pivots=cs1-bash
I'm trying to connect to the database from my local machine (not in a container) using Python. I've tried various iterations, but the connection script is generally:
import pyodbc
server = 'localhost,1433'
database = 'TestDB'
username = 'sa'
password = '<YourStrong@Passw0rd>'
cnxn = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};SERVER='+server+';DATABASE='+database+';UID='+username+';PWD='+ password)
cursor = cnxn.cursor()
Which generates a pyodbc error:
pyodbc.OperationalError: ('HYT00', '[HYT00] [Microsoft][ODBC Driver 17 for SQL Server]Login timeout expired (0) (SQLDriverConnect)')
I've checked the driver is correct
mssql@sql1:/$ cat /etc/odbcinst.ini
[ODBC Driver 17 for SQL Server]
Description=Microsoft ODBC Driver 17 for SQL Server
Driver=/opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.9.so.1.1
UsageCount=1
And checked that the ports are open.
Can anyone help with how to make this connection work?
发布评论