[英]Database connection failed for local MSSQL server with pymssql
I had been working with pyodbc
for database connection in windows envirnment and it is working fine but now I want to switch to pymssql
so that it is easier to be deployed to Linux machine as well.我一直在使用
pyodbc
在 windows 环境中进行数据库连接,它工作正常,但现在我想切换到pymssql
以便它也更容易部署到 Linux 机器上。 But I am getting this error:但我收到此错误:
(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')
(20009, b'DB-Lib 错误消息 20009, 严重性 9:\\n无法连接: Adaptive Server 不可用或不存在 (localhost:1433)\\n在未知错误 (10060) 期间出现 Net-Lib 错误 (10060)\\n')
My connection code for using both pyodbc
and pymssql
is:我使用
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
What could be the problem?可能是什么问题呢? And solution?
和解决方案?
Well after browsing internet for a while, it seems pymssql
needs TCP/IP be enabled for communication.好吧,在浏览了一段时间后,
pymssql
似乎需要启用 TCP/IP 才能进行通信。
instance_name
instance_name
协议TCP/IP
TCP/IP
I have faced the same issue while using RDS(AWS database instance).
我在使用 RDS(AWS 数据库实例)时遇到了同样的问题。 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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.