Django数据库与主机的连接和SQL实例

2024-04-25 19:08:51 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用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:

在设置.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',
        },
    }
}

如何解决此错误并连接到数据库?你知道吗


Tags: or文件theinstancepyclient数据库sql
1条回答
网友
1楼 · 发布于 2024-04-25 19:08:51

自从你的设置.py看起来不错,我认为这是一个普遍的问题,可能是由数据库端的多个错误配置引起的,例如:

  • SQL Server配置管理中禁用了TCP/IP连接
  • 在TCP/IP属性中,无法配置端口1433,因此它拒绝您的请求
  • 许多SQL windows服务中的一个可能突然停止

我发现this stack overflow的帖子非常有用,有多个答案,涵盖了以上每一点。你知道吗

相关问题 更多 >