其他主题

Geting Data from MSSQL Using pyodbc Error

待回答 0 个回答

较早的帖子,发布于 2017年3月30日。 其中的信息可能已经过时。

本帖暂无中文翻译,以下为英文原文。

问题 提问于 2017年3月30日

I am using pyodbc to retrieve data from MSSQL and this is the code I am using: 

import pyodbc

server = 'XXXXXXXXX\DEV,43853'

#server = 'XXXXXXXXX\DEV'

#Also used second server statement and got same error.

database = 'SandBox'
username = 'Username'
password = 'password'

driver = '{SQL Server}'

cnxn = pyodbc.connect('DRIVER='+driver+';SERVER='+server+';DATABASE='+database+';UID='+username+';PWD='+ password)

#cnxn = pyodbc.connect('DRIVER='+driver+';PORT=43853;SERVER='+server+';PORT=43853;DATABASE='+database+';UID='+username+';PWD='+ password)

#Also Used cnxn second statement and got the same error

cursor = cnxn.cursor()
cursor.execute("select * from fieldscreenscheme ")
row = cursor.fetchone()
if row:
    print row

This is the error massage I got:

Traceback (most recent call last):

cnxn = pyodbc.connect('DRIVER='+driver+';SERVER='+server+';DATABASE='+database+';UID='+username+';PWD='+ password)

pyodbc.Error: ('08001', '[08001] [Microsoft][ODBC SQL Server Driver][DBNETLIB]Specified SQL server not found. (6) (SQLDriverConnect); [01000] [Microsoft][ODBC SQL Server Driver][DBNETLIB]ConnectionOpen (Connect()). (11001)')

I installed the ODBC driver. The created the SYSTEM DSN and when it completes test successfully, but the python code does not work. Any recommendation how to solve the error? 

Microsoft Documentation: https://docs.microsoft.com/en-us/azure/sql-database/sql-database-connect-query-python



暂无回答

撰写回答

您的邮箱地址不会被公开。请勿发布密码。

This site uses Akismet to reduce spam. Learn how your comment data is processed.