Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

python - Pyodbc error Data source name not found and no default driver specified 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)')

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

My system links are as follows:

This is what the system DNS looks like

My code is:

import os
import sys
import time
import pyodbc

LOCATION = "c:UsersMarcelloDesktopDATAScorMonitor.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
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Two thoughts on what to check:

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

  • On a typical client PC, open Control Panel -> Administrative Tools -> Data Sources.
  • Select the File DSN tab and click Add.
  • Select the appropriate driver (e.g. "Microsoft Access Driver (*.mdb)") and click Next
  • Click Browse and choose where you want to save the .dsn file (this is a temporary file you are going to delete later).
  • Click Next then Finish.
  • You will be shown the vendor-specific ODBC setup dialog. For example, with Microsoft Access, you might only need to click Select and browse to an existing .mdb file before clicking OK.
  • Browse to the location of the .dsn file and open using Notepad.

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. Omit the first [ODBC] line
  2. Put curly braces around all values containing spaces
  3. Put all name=value pairs on one line, separated by semicolons.

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 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...