是否可以在 Python 中将 SQLite3 与 Microsoft SQL Server 一起使用?

Stu*_*ent 2 python sql-server sqlite ipython

我正在尝试使用 SQLite3 模块连接到 Microsoft SQL Server。

一切似乎都被识别了,但无论出于何种原因它都无法识别我的列或表。

import sqlite3
con = sqlite3.connect('V7.0.6_X2_857I.sql')
cur = con.cursor()
cur.execute("""SELECT * FROM TS857_5400""")
all = cur.fetchall()
print one
Run Code Online (Sandbox Code Playgroud)

但是,我遇到了这个错误:

---------------------------------------------------------------------------
OperationalError                          Traceback (most recent call last)
<ipython-input-39-04a8789e04a7> in <module>()
      3 con = sqlite3.connect('V7.0.6_X2_857I.sql')
      4 cur = con.cursor()
----> 5 cur.execute("""SELECT * FROM TS857_5400""")
      6 all = cur.fetchall()
      7 print one

OperationalError: no such table: TS857_5400
Run Code Online (Sandbox Code Playgroud)

我知道这个表存在,所以我想知道这是否是声明的连接字符串的问题或 SQLite3(使用 SQL Server)的限制。

先感谢您。

Mar*_*ers 5

SQLite 是一个完全不同的数据库,请参见http://www.sqlite.org/;该sqlite3模块与 Microsoft SQL Server无关,而是与嵌入式数据库有关。

换句话说,您无法使用该sqlite3模块连接到 SQL Server。

您需要安装第 3 方库才能连接。Python Wiki列出了多个选项,从 ODBC 驱动程序到 SQL Server 专用连接器。哪一种适合您取决于您​​的 Python 版本和当前操作系统。