在Windows上从python连接到odbc的常见方法?

发布于 2024-07-17 07:23:00 字数 1542 浏览 4 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

半世晨晓 2024-07-24 07:23:00

您已经建议了 pyodbc,我同意您的观点。

在我的经验中,它给我带来的问题最少; 我使用过 pymssqladodbapi,当这些抛出异常/创建问题时,我交换了代码并将其替换为 pyodbc,它要么解决了问题,要么提供了更好的错误消息,以便我可以更快地调试。

值得一提的是,我主要用它来连接MSSQL Server数据库。

You already suggested pyodbc, and I am going to agree with you.

It has given me the least amount of issues in my experience; I've used pymssql and adodbapi, and when those threw exceptions/created issues, I swapped out the code and replaced it with pyodbc and it either fixed the problem, or gave better error messages so I could debug faster.

It's worth mentioning that I primarily use it to connect to MSSQL Server DBs.

小兔几 2024-07-24 07:23:00

我使用 SQLAlchemy 进行所有 python 数据库访问。 我强烈推荐 SQLAlchemy。

连接到 SQL Server 数据库时,SA 在底层使用 pyodbc。 它使用其他 DBAPI 库连接到其他数据库,例如 cx_Oracle。

一个简单的例子,像通常使用 DBAPI 模块一样使用 SQLAlchemy:

import sqlalchemy

engine = sqlalchemy.create_engine('sqlite:///database.db')
for r in engine.execute('SELECT * FROM T'):
    print(r.OneColumn, r.OtherColumn)

但是 SQLAlchemy 的真正价值在于它的 ORMSQL 表达式语言。 看看吧,非常值得花功夫去学习使用。

I use SQLAlchemy for all python database access. I highly recommend SQLAlchemy.

SA uses pyodbc under the hood when connecting to SQL server databases. It uses other DBAPI libraries to connect to other database, for instance cx_Oracle.

A simplistic example, using SQLAlchemy like you would normally use a DBAPI module:

import sqlalchemy

engine = sqlalchemy.create_engine('sqlite:///database.db')
for r in engine.execute('SELECT * FROM T'):
    print(r.OneColumn, r.OtherColumn)

But the real value of SQLAlchemy lies in its ORM and SQL expression language. Have a look, it is well worth the effort to learn to use.

通知家属抬走 2024-07-24 07:23:00

另一种选择是 pypyodbc ,它是用纯 Python 编写的。 它可以看作是pyodbc模块的重新实现——只有大约1800行代码,有利于维护。

这是在Python中访问mssql的Hello World示例。

Another alternative is pypyodbc which was written in pure Python. it can been seen as a re-implemenation of the pyodbc module – with only around 1800 lines code, which is good for maintenance.

Here's a Hello World sample of accessing mssql in Python.

维持三分热 2024-07-24 07:23:00

我在工作中使用 pyodbc,它从来没有让我失望过(我们有各种数据库)。 它坚固且快速。

它得到积极维护,并且 python 3 版本即将推出。

如果您想要具有付费支持的“企业”软件,您可以使用 mxODBC

I use pyodbc at work and it has never failed me (we have varius dbs). It is robust and fast.

It is actively maintained and a python 3 version will come soon.

If you want "enterprise" software with payed support you can use mxODBC.

菩提树下叶撕阳。 2024-07-24 07:23:00

您可以尝试一下 turbodbc。 从1.1.1版本开始,正式支持Windows。 对于您所做的事情来说,它很有可能比 pyodbc 更快。

You can give turbodbc a spin. Since version 1.1.1, it officially supports Windows. There's a good chance that it is faster than pyodbc for what you do.

街角卖回忆 2024-07-24 07:23:00

pyodbc 现在支持 Python 3!

Python 3 is now supported by pyodbc!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文