Pyodbc 错误数据源名称未找到且未指定默认驱动程序悖论 [英] Pyodbc error Data source name not found and no default driver specified paradox

查看:80
本文介绍了Pyodbc 错误数据源名称未找到且未指定默认驱动程序悖论的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 pyobdc 从 paradox 数据库中读取数据,但在尝试连接到数据库时不断收到以下错误:

I am attempting to use pyobdc to read data from a paradox database, and I keep getting the following error when attempting to connect to the database:

pyodbc.Error: ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (0) (SQLDriverConnect)')

我曾尝试为数据库创建新的 DNS 链接,但一直没有帮助.

I have tried to create new DNS links for the database but it has not helped what so ever.

我的系统链接如下:

我的代码是:

import os
import sys
import time
import pyodbc

LOCATION = "c:\Users\Marcello\Desktop\DATA\ScorMonitor.db"

cnxn = pyodbc.connect(r"Driver={{Microsoft Paradox Driver (*.db )}};Fil=Paradox 5.X;DefaultDir={0};Dbq={0}; CollatingSequence=ASCII;")
cursor = cnxn.cursor()
cursor.execute("select last, first from test")
row = cursor.fetchone()
print row

推荐答案

关于检查内容的两个想法:

Two thoughts on what to check:

1) 您的连接字符串错误.有一种方法可以直接从 ODBC 管理器程序(取自 http://www.visokio.com/kb/db/dsn-less-odbc).这些说明假设您使用的是 MDB,但同样的过程也适用于悖论文件

1) Your connection string is wrong. There's a way to get a known good connection string directly from the ODBC Administrator program (taken from http://www.visokio.com/kb/db/dsn-less-odbc). These instructions assume you're using an MDB, but the same process will work for a paradox file

  • 在典型的客户端 PC 上,打开控制面板 -> 管理工具 -> 数据源.
  • 选择文件 DSN 选项卡,然后单击添加.
  • 选择合适的驱动程序(例如Microsoft Access Driver (*.mdb)")并点击下一步
  • 单击浏览"并选择要保存 .dsn 文件的位置(这是您稍后要删除的临时文件).
  • 点击下一步,然后点击完成.
  • 您将看到特定于供应商的 ODBC 设置对话框.例如,对于 Microsoft Access,您可能只需要在单击确定"之前单击选择"并浏览到现有的 .mdb 文件.
  • 浏览到 .dsn 文件的位置并使用记事本打开.

在 DSN 文件中,您可能会看到类似于:

In the DSN file you might see something similar to:

[ODBC]
DRIVER=Microsoft Access Driver (*.mdb)
UID=admin
UserCommitSync=Yes
Threads=3
SafeTransactions=0
PageTimeout=5
MaxScanRows=8
MaxBufferSize=2048
FIL=MS Access
DriverId=25
DefaultDir=C:\
DBQ=C:\db1.mdb

将上面的转换为完整的连接字符串:

To convert the above to the full connection strring:

  1. 省略第一行 [ODBC]
  2. 用花括号将所有包含空格的值括起来
  3. 将所有名称=值对放在一行,用分号分隔.

这为您提供了完整的连接字符串.在这个例子中,字符串变成:

This gives you the full connection string. In this example, the string becomes:

DRIVER={Microsoft Access Driver (*.mdb)};UID=admin;UserCommitSync=Yes;Threads=3;SafeTransactions=0;PageTimeout=5;axScanRows=8;MaxBufferSize=2048;FIL={MS Access};DriverId=25;DefaultDir=C:\;DBQ=C:\db1.mdb

2) 32/64 位不匹配.我在将 32 位 python 与 64 位驱动程序混合时遇到了麻烦,反之亦然.您可能需要检查您的 Python 解释器和数据库驱动程序.

2) 32/64 bit mismatch. I've had troubles when mixing 32-bit python with 64-bit drivers, or vice-versa. You may want to check your Python interpreter and database driver line up.

这篇关于Pyodbc 错误数据源名称未找到且未指定默认驱动程序悖论的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆