【发布时间】:2019-12-16 08:19:41
【问题描述】:
我使用 SQL Server 作为数据库的后端。在setting.py 文件中,我需要将主机名与实例一起使用。因此,我得到了下面给出的错误,
The above exception (('08001', '[08001] [Microsoft][SQL Server Native Client 11.0]TCP Provider: No connection could be made because the target machine actively refused it.\r\n (10061) (SQLDriverConnect); [08001] [Microsoft][SQL Server Native Client 11.0]Login timeout expired (0); [08001] [Microsoft][SQL Server Native Client 11.0]Invalid connection string attribute (0); [08001] [Microsoft][SQL Server Native Client 11.0]A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online. (10061)')) was the direct cause of the following exception:
在setting.py文件中,
DATABASES = {
'default': {
'ENGINE': 'sql_server.pyodbc',
'NAME': 'xxxxx',
'USER': 'xxx',
'PASSWORD': 'xxxx',
'PORT': '1433',
'HOST': 'aaa\bbb',(hostname\instance)
'OPTIONS': {
'driver': 'SQL Server Native Client 11.0',
},
}
}
如何解决此错误并连接到我的数据库?
【问题讨论】:
-
您是否检查过您的主机上的端口 1433 是否打开?
-
是的。它是开放的
-
有一个新的答案可以直接解决这个问题,你可以选择接受它或者忽略它/点赞
标签: python sql-server django django-pyodbc-azure