【发布时间】:2019-01-02 21:25:25
【问题描述】:
我正在使用pypyodbc 库建立与 SQL Server 2008 R2 数据库的连接,每次尝试执行 .sql 文件时都会遇到以下错误:
pypyodbc.ProgrammingError: ('42000', "[42000] [Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near 'Go'.")
这是我要执行的 sql 查询:
Use SL_Site1_App
Go
select emp_num,name, trans_num, job, trans_type
from Hours where trans_type like '1000%' order by trans_date desc
这是我正在使用的 python 脚本:
import pypyodbc, ExcelFile
def main():
# read the SQL queries externally
queries = ['C:\\Temp\\Ready_to_use_queries\\Connection_sql_python.sql']
for index, query in enumerate(queries):
cursor = initiate_connection_db()
results = retrieve_results_query(cursor, query)
if index == 0:
ExcelFile.write_to_workbook(results)
print("The workbook has been created and data has been inserted.\n")
def initiate_connection_db():
connection_live_db = pypyodbc.connect(driver="{SQL Server}", server="xxx.xxx.xxx.xxx", uid="my-name",
pwd="try-and-guess", Trusted_Connection="No")
connection = connection_live_db.cursor()
return connection
解决此问题的方法是删除 Use SL_Site1_App Go 行,但我想知道这是否是与处理这些行的 pypyodbc 库相关的已知问题,如果是,我应该在哪里通知开发人员问题。
【问题讨论】:
标签: sql-server python-3.x pypyodbc