我正在尝试测试将数据帧推送到SQL Server的脚本。
这是我到目前为止所做的:
import pandas as pd
import pyodbc
conn_str = (
r'Driver={SQL Server};'
r'SERVER=wouldntuliketoknow\SQLEXPRESS;'
r'Database=test;'
r'Trusted_Connection=yes;'
)
cnxn = pyodbc.connect(conn_str)
cursor = cnxn.cursor()
globalID = [9581091, 9581091, 79735371, 79735371, 79735371]
ID = [53506312, 961273620, 53506312, 79735371, 135962137]
names = ['meh',
'cool',
'dude whatever',
'foo',
'bar']
df = pd.DataFrame({'globalID': globalID, 'ID': ID, 'name': names})
df.to_sql("pandas", cnxn)
print(conn_str)
这是一个错误:
pandas.io.sql.DatabaseError:sql上的执行失败'SELECT name FROM sqlite_master WHERE type ='table'AND name =?;':('42S02',“[42S02] [Microsoft] [ODBC SQL Server驱动程序] [SQL Server]无效的对象名称'sqlite_master'。(208)(SQLExecDirectW)“)
我做错了什么?
我不确定sqllite_master在错误中的来源?
光标是否必要?