pymssql._pymssql.OperationalError: (20009, b’DB-Lib error message 20009, severity 9:\nUnable to conn
severity 9:\nAdaptive Server connection failed
打开sql server 配置管理器。
将TPC/IP 启用
import pyodbc
Replace ‘server_name’, ‘database_name’, ‘username’, and ‘password’ with your server name, database name, username, and password
conn = pyodbc.connect(‘DRIVER={ODBC Driver 17 for SQL Server};SERVER=server_name;DATABASE=database_name;UID=username;PWD=password’)
cursor = conn.cursor()# Replace ‘table_name’ with the name of your table
cursor.execute(‘SELECT * FROM table_name’)
for row in cursor:
print(row)
Close the connectionconn.close()