小编Nei*_*l S的帖子

使用 odbc_connect 从 SQLAlchemy 连接到 SQL 服务器

我是 Python 和 SQL 服务器的新手。在过去的 2 天里,我一直在尝试将 Pandas df 插入到我们的数据库中,但没有任何运气。任何人都可以帮我调试错误。

我已经尝试了以下

import pyodbc
from sqlalchemy import create_engine

engine = create_engine('mssql+pyodbc:///?odbc_connect=DRIVER={SQL Server};SERVER=bidept;DATABASE=BIDB;UID=sdcc\neils;PWD=neil!pass')
engine.connect()
df.to_sql(name='[BIDB].[dbo].[Test]',con=engine, if_exists='append')
Run Code Online (Sandbox Code Playgroud)

但是在 engine.connect() 行我收到以下错误

sqlalchemy.exc.DBAPIError: (pyodbc.Error) ('08001', '[08001] [Microsoft][ODBC SQL Server Driver]Neither DSN nor SERVER keyword supplied (0) (SQLDriverConnect)')
Run Code Online (Sandbox Code Playgroud)

谁能告诉我我错过了什么。我正在使用 Microsoft SQL Server Management Studio - 14.0.17177.0

我通过以下方式连接到SQL服务器

Server type: Database Engine
Server name: bidept
Authentication: Windows Authentication

for which I log into my windows using username : sdcc\neils
and password : neil!pass
Run Code Online (Sandbox Code Playgroud)

我也试过这个

import pyodbc

conn_str …
Run Code Online (Sandbox Code Playgroud)

python sql-server sqlalchemy pyodbc pandas

4
推荐指数
1
解决办法
4639
查看次数

标签 统计

pandas ×1

pyodbc ×1

python ×1

sql-server ×1

sqlalchemy ×1