使用 pymssql 的本地 MSSQL 服务器的数据库连接失败
Database connection failed for local MSSQL server with pymssql
我一直在 pyodbc
环境中使用 pyodbc
进行数据库连接,它工作正常,但现在我想切换到 pymssql
以便更容易部署Linux 机器也是如此。但我收到此错误:
(20009, b'DB-Lib error message 20009, severity 9:\nUnable to connect: Adaptive Server is unavailable or does not exist (localhost:1433)\nNet-Lib error during Unknown error (10060)\n')
我同时使用 pyodbc
和 pymssql
的连接代码是:
import pyodbc
import pymssql
def connectODSDB_1():
conn_str = (
r"Driver={SQL Server};"
r"Server=(local);"
r"Database=populatedSandbox;"
r"Trusted_Connection=yes;"
)
return pyodbc.connect(conn_str)
def connectODSDB_2():
server = '(local)'
database = 'populatedSandbox'
conn = pymssql.connect(server=server, database=database)
return conn
可能是什么问题?和解决方案?
嗯,上网浏览了一会儿,看来 pymssql
需要启用 TCP/IP 才能进行通讯。
- 打开Sql服务器配置管理器
- 展开SQL服务器网络配置
- 单击
instance_name
的协议
- 启用
TCP/IP
I have faced the same issue while using RDS(AWS database instance). We should configured the inbound outbound rules.
Do following steps to configure.
Services->RDS->DB Instances -> Select DB-> Connectivity&Security
Under Security Section
VPC security groups -> click on security group
Change the inbound rules.
Check the source IP and change into anywhere or specific IP
我一直在 pyodbc
环境中使用 pyodbc
进行数据库连接,它工作正常,但现在我想切换到 pymssql
以便更容易部署Linux 机器也是如此。但我收到此错误:
(20009, b'DB-Lib error message 20009, severity 9:\nUnable to connect: Adaptive Server is unavailable or does not exist (localhost:1433)\nNet-Lib error during Unknown error (10060)\n')
我同时使用 pyodbc
和 pymssql
的连接代码是:
import pyodbc import pymssql def connectODSDB_1(): conn_str = ( r"Driver={SQL Server};" r"Server=(local);" r"Database=populatedSandbox;" r"Trusted_Connection=yes;" ) return pyodbc.connect(conn_str) def connectODSDB_2(): server = '(local)' database = 'populatedSandbox' conn = pymssql.connect(server=server, database=database) return conn
可能是什么问题?和解决方案?
嗯,上网浏览了一会儿,看来 pymssql
需要启用 TCP/IP 才能进行通讯。
- 打开Sql服务器配置管理器
- 展开SQL服务器网络配置
- 单击
instance_name
的协议
- 启用
TCP/IP
I have faced the same issue while using RDS(AWS database instance). We should configured the inbound outbound rules. Do following steps to configure.
Services->RDS->DB Instances -> Select DB-> Connectivity&Security
Under Security Section
VPC security groups -> click on security group
Change the inbound rules.
Check the source IP and change into anywhere or specific IP