如何修复 'Named Pipes Provider: Could not open a connection to SQL Server [53]'?

How to fix 'Named Pipes Provider: Could not open a connection to SQL Server [53]'?

我无法将 MSsql 数据库连接到 Django。

当我尝试使用 python 时,效果很好,但是当我尝试使用 Django 上的 运行 服务器时,出现错误。

Pyodbc 版本:4.0.27; Django 版本:2.1.13; 微软 SQL 服务器 2017 (RTM) - 14.0.1000.169 (X64)。

DATABASES = {
    'default': {
        'ENGINE': 'sql_server.pyodbc',
        'NAME': '<djangoBanks>',
        'HOST': '<DESKTOP-0FKB14V>',
        'USER': '<test>',
        'PASSWORD': '<12345>',

        'OPTIONS': {
            'driver': "ODBC Driver 17 for SQL Server",
            'Trusted_Connection' : 'Yes',
        }
    }
}

当我尝试 运行 python manage.py runserver 时出现此错误:

'08001', '[08001] [Microsoft][ODBC Driver 17 for SQL Server]Named Pipes Provider: Could not open a connection to SQL Server [53]. (53) (SQLDriverConnect); [08001] [Microsoft][ODBC Driver 17 for SQL Server]Login timeout expired (0); [08001] [Microsoft][ODBC Driver 17 for SQL Server]Invalid connection string attribute (0); [08001] [Microsoft][ODBC Driver 17 for SQL Server]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. (53)'

我编辑了 'Options' 然后它开始工作了。

DATABASES = {
    'default': {
        'ENGINE': 'sql_server.pyodbc',
        'NAME': 'djangoBanks',
        'HOST': 'DESKTOP-0FKB14V',
        'USER': 'test',
        'PASSWORD': '12345',

    'OPTIONS': {
            'driver': "ODBC Driver 17 for SQL Server",
            'SERVER' : 'DESKTOP-0FKB14V',
            'DATABASE' : 'djangoBanks',
            'UID' : 'test',
            'PWD' : '12345',
            'Trusted_Connection' : 'Yes',
        }
    }
}