網頁

2019年3月4日 星期一

[已解決] Unable to connect: Adaptive Server is unavailable or does not exist (172.0.0.1:1433)

今天想要從 Python 去連 Microsoft Sql Server , 從 Anaconda 命令列視窗安裝了 pymssql , 從 Spyder Console 中下指令 :



import pymssql as db
db.connect(host='127.0.0.1', user='sa', password='1234', charset='utf8', databse='MXF')

結果連不上 Database , 錯誤訊息如下 :

db.connect(host='172.0.0.1:1433',user='sa',password='1234',database='MXF')
Traceback (most recent call last):

  File "<ipython-input-4-54f0d3201e7b>", line 1, in <module>
    db.connect(host='172.0.0.1:1433',user='sa',password='1234',database='MXF')

  File "src\pymssql.pyx", line 642, in pymssql.connect

OperationalError: (20009, b'DB-Lib error message 20009, severity 9:\nUnable to connect: Adaptive Server is unavailable or does not exist (172.0.0.1:1433)\nNet-Lib error during Unknown error (10060)\n')

我的系統環境如下 :
Windows 10 Home Edition
Microsoft SQL Server 2017 Express
Python 3.6.7
pymssql 2.1.4

解決方法如下 :
1. 從 [Sql Server Configuration Manager] => [SQL Server 網路組態] => [SQLEXPRESS的通訊協定] => [TCP/IP]  中 , 確定 IP位址 127.0.0.1 [已啟用] 且 [使用中] , 然後在 IPAll 的 [TCP通訊埠] 中填入 [1433] .
2. 重新啟動 [SQL Server 服務]

正確的連線語法如下 :

import pymssql as db

db.connect(server='127.0.0.1', user='sa', password='1234', charset='utf8', database='MXF', port='1433')







1 則留言:

  1. To open configuration manager in SQL Server 2017, press the Windows and R key together. In Run, type “SQLServerManager14.msc” command.

    回覆刪除