cnxn = pyodbc.connect('DRIVER={ODBC Driver 11 for SQL Server};SERVER='+server+';DATABASE='+database+';UID='+username+';PWD='+ password)
噗嗤。接口错误:
("IM002", "[IM002] [Microsoft][ODBC 驱动程序管理器] 数据源名称 未找到且未指定默认驱动程序 (0) (SQLDriverConnect)')
这应该可以正常工作:
import pytds
SERVER.IP = 'xx.xxx.xxx.xxx'
SERVER.DB_NAME = 'xxxxxx'
SERVER.USERNAME = 'xxxx'
SERVER.PWD = 'xxxxxx'
with pytds.connect(SERVER.IP, SERVER.DB_NAME, SERVER.USERNAME, SERVER.PWD) as conn:
cursor = conn.cursor()
if conn == False:
print("Error, Could not connect to the database")
else:
print("Connected to DB")