Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
MS access db
#1
Hi,
This question has been asked a 1000 times over the years in various forums.
I had hoped that with python 3.10 things would be smoother. I still can't make it work.
Problem:
I have been given a database with 20 tables with many records in them.
(Genealogical data 16th -18th century.)
In the 16th century a local administrator decided to put all these data in MS access with extension '.accdb'
I imported pyodbc: ok
Then check if drivers are available: ok
print([x for x in pyodbc.drivers() if x.startswith('Microsoft Access Driver')])
Output:
['Microsoft Access Driver (*.mdb, *.accdb)']
Then I try to read the database with the code provided in the pyodbc site, and get the message:
Error:
Traceback (most recent call last): File "D:\FV\20220324 FV\PyOdbc.py", line 28, in <module> conn = pyodbc.connect(r'Driver={Microsoft Access Driver (*.mdb, *.accdb)}') pyodbc.Error: ('HY000', 'The driver did not supply an error!')
I have devised a workaround to get to the data, but it would be faster if I could read them directly.
Any ideas?
thx,
Paul
It is more important to do the right thing, than to do the thing right.(P.Drucker)
Better is the enemy of good. (Montesquieu) = French version for 'kiss'.
Reply
#2
There are several tutorials that can be found with google query: 'read and write "MS Access" python 3'
here's one that's randomly selected
lots's of advertising, but on quick inspection appears to cover the basics.
Reply
#3
Thanks for trying to help Larz, but I visited several of these tutorials,
and they all are clones of the same source, it would seem.
They also all give the same error.
Some sites that I visited recommend the no-nonsense approach,
just dump it as a csv, and get on with it.
Sound advice.
Paul
It is more important to do the right thing, than to do the thing right.(P.Drucker)
Better is the enemy of good. (Montesquieu) = French version for 'kiss'.
Reply
#4
From the error traceback It looks your line conn = pyodbc.connect(r'Driver={Microsoft Access Driver (*.mdb, *.accdb)}') does not specify any MS Access file to connect to., e.g. the same line in the tutorial refered by Larz the connection string is con_string = r'DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=C:\Users\parwizforogh\Documents\pydb.accdb;'

Same in the pyodbc docs:
https://github.com/mkleehammer/pyodbc/wi...oft-Access

Fix your connection string.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#5
Yes, a db is required. That much even I know.
 con_string = r'DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=Bx.accdb;'
conn = pyodbc.connect(con_string)
There must be something else not working, otherwise there would not be hundreds of the same
posts in various forums.
Sometimes the use of DBFtools is recommended. Sometimes it is recommended to stay away from it.
Even "import pandas_access" does not cut it.
Python and MS acces are not friends.
Paul
It is more important to do the right thing, than to do the thing right.(P.Drucker)
Better is the enemy of good. (Montesquieu) = French version for 'kiss'.
Reply
#6
(Mar-25-2022, 04:46 PM)DPaul Wrote: Yes, a db is required. That much even I know.
It was not evident from the error message. There was no DBQ part in your code.


(Mar-25-2022, 04:46 PM)DPaul Wrote: There must be something else not working, otherwise there would not be hundreds of the same posts in various forums.

As mentioned in many of these posts all over the place - pyodbc.Error: ('HY000', 'The driver did not supply an error!') is generic error and may be raised for many reasons
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#7
Don't worry, dump it as a csv and don't look back.

However, another surprise has surfaced. After the French
Revolution (1789) the Revolutionaries decided to restart the calendar from zero.
They renamed the months, and had to fiddle around in the final days of a year,
because they did not get to 365 days total with their new system.

So the guy that started the MS access table faithfully copied eg. " 1 ventôse, year 2 ".
Does anybody think that can be converted with the datetime module ? Cool
Paul
It is more important to do the right thing, than to do the thing right.(P.Drucker)
Better is the enemy of good. (Montesquieu) = French version for 'kiss'.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020