我正在尝试使用Python代码连接到SQL Server:
import pyodbc
cnxn = pyodbc.connect('DRIVER={SQL Server};SERVER=digitest-02;DATABASE=test;UID=sa;PWD=test@#^%$')
cursor = cnxn.cursor()
cursor.execute('SELECT * FROM wellsfargo.dbo.predictions')
for row in cursor:
print(row)
但是出现错误而不是连接输出:
C:\Users\BhaskarDas\PycharmProjects\SQLConnector_RW\venv\Scripts\python.exe C:/Users/BhaskarDas/PycharmProjects/SQLConnector_RW/SQLReadWrite.py
Traceback (most recent call last):
File "C:/Users/BhaskarDas/PycharmProjects/SQLConnector_RW/SQLReadWrite.py", line 3, in <module>
cnxn = pyodbc.connect('DRIVER={SQL Server};SERVER=digitest-02;DATABASE=test;UID=sa;PWD=test@#^%$')
pyodbc.OperationalError: ('08001', '[08001] [Microsoft][ODBC SQL Server Driver][DBNETLIB]SQL Server does not exist or access denied. (17) (SQLDriverConnect); [08001] [Microsoft][ODBC SQL Server Driver][DBNETLIB]ConnectionOpen (Connect()). (53)')
Process finished with exit code 1
答案 0 :(得分:0)
当我指定服务器IP地址而不是服务器名称时,它可以正常工作。