我的引擎参数有问题:
import pyodbc
import pandas as pd
from sqlalchemy import create_engine
import urllib
conn_str = (
r'Driver=ODBC Driver 11 for SQL Server;'
r'Server=Saturn;'
r'Database=ExperienceRating2019;'
r'Trusted_Connection=yes;'
)
quoted_conn_str = urllib.parse.quote_plus(conn_str)
engine = create_engine('mssql+pyodbc:///?odbc_connect={}'.format(quoted_conn_str)).execution_options(autocommit=True)
cnxn = engine.connect()
splitpoint = 17000
excel_file = "#2 DRATIO RUN.xlsx"
d_ratio_sheet = "D RATIO & ELR"
d_ratio = pd.read_excel(open(excel_file,'rb'),sheet_name = d_ratio_sheet)
d_ratio.to_sql("d_ratio", cnxn, if_exists = 'replace')
我将收到以下错误:
DBAPIError:(pyodbc.Error)('HY010','[HY010] [Microsoft] [SQL Server的ODBC驱动程序11]功能序列错误(0)(SQLFetch)')(此错误的背景位于:{{ 3}})
如果我更改引擎以丢失自动提交
engine = create_engine('mssql+pyodbc:///?odbc_connect={}'.format(quoted_conn_str))
错误消失了(是!),但是稍后在我执行SP的代码中,它将不再提交:
engine.execute("sp_refresh_inputs")
**问题:**如何更改我的连接以使pandas和sqlalchemy都能正常工作?
答案 0 :(得分:0)
我最终使用了两种引擎,一种用于熊猫,另一种用于sqlalchemy:
.column