大家好我现在正在使用Pandas和MSSQL。我有好的工作,但最近在SQlalchemy更新后,当我尝试通过df.to_sql将信息上传到数据库时,我收到以下错误
pyodbc.Error :(' HY000','驱动程序未提供错误!')
我的连接定义如下
engine = create_engine('mssql+pyodbc://Reporter:******@localhost:1433/SourcingDb?driver=SQL+Server')
df.to_sql(' ProductivityDeck',con = engine,if_exists =' replace',index = False)
我得到的完整错误就是这个
Traceback (most recent call last):
文件" C:\ Python \ Python36 \ lib \ site-packages \ sqlalchemy \ engine \ base.py",第1182行,在_execute_context中 上下文) 文件" C:\ Python \ Python36 \ lib \ site-packages \ sqlalchemy \ engine \ default.py",第470行,在do_execute中 cursor.execute(语句,参数) pyodbc.Error :(' HY000','驱动程序没有提供错误!')
上述异常是导致以下异常的直接原因:
Traceback (most recent call last):
File "C:/Users/H212310/PycharmProjects/untitled2/UpdateCEDeckv2.py", line 23, in <module>
df.to_sql('ProductivityDeck', con=engine, if_exists='replace', index= False)
File "C:\Python\Python36\lib\site-packages\pandas\core\generic.py", line 2127, in to_sql
dtype=dtype)
File "C:\Python\Python36\lib\site-packages\pandas\io\sql.py", line 450, in to_sql
chunksize=chunksize, dtype=dtype)
File "C:\Python\Python36\lib\site-packages\pandas\io\sql.py", line 1149, in to_sql
table.insert(chunksize)
File "C:\Python\Python36\lib\site-packages\pandas\io\sql.py", line 663, in insert
self._execute_insert(conn, keys, chunk_iter)
File "C:\Python\Python36\lib\site-packages\pandas\io\sql.py", line 638, in _execute_insert
conn.execute(*self.insert_statement(data, conn))
File "C:\Python\Python36\lib\site-packages\sqlalchemy\engine\base.py", line 945, in execute
return meth(self, multiparams, params)
File "C:\Python\Python36\lib\site-packages\sqlalchemy\sql\elements.py", line 263, in _execute_on_connection
return connection._execute_clauseelement(self, multiparams, params)
File "C:\Python\Python36\lib\site-packages\sqlalchemy\engine\base.py", line 1053, in _execute_clauseelement
compiled_sql, distilled_params
File "C:\Python\Python36\lib\site-packages\sqlalchemy\engine\base.py", line 1189, in _execute_context
context)
File "C:\Python\Python36\lib\site-packages\sqlalchemy\engine\base.py", line 1402, in _handle_dbapi_exception
exc_info
File "C:\Python\Python36\lib\site-packages\sqlalchemy\util\compat.py", line 203, in raise_from_cause
reraise(type(exception), exception, tb=exc_tb, cause=cause)
File "C:\Python\Python36\lib\site-packages\sqlalchemy\util\compat.py", line 186, in reraise
raise value.with_traceback(tb)
File "C:\Python\Python36\lib\site-packages\sqlalchemy\engine\base.py", line 1182, in _execute_context context)
File "C:\Python\Python36\lib\site-packages\sqlalchemy\engine\default.py", line 470, in do_execute
cursor.execute(statement, parameters)
我曾尝试回滚到较低版本的SqlAlchemy,在Windows中更新ODBC驱动程序并升级python安装并继续回来。
有关如何解决此问题的任何想法?
答案 0 :(得分:2)
好的,这是“pandas 23中已知错误的无声错误,降级到v22会导致错误消失,您可以上传1000多行。
正在制定
答案 1 :(得分:0)
我有相同的错误(“ HY000”,“驱动程序未提供错误!”)。一些StackOverflow线程上的现有解决方案没有帮助。
就我而言,错误来自pyodbc.connect()
。
我最终重新安装了python和依赖项,问题消失了。
答案 2 :(得分:0)
pyodbc.connect('Driver={ODBC Driver 17 for SQL Server};')
换司机对我有用!