简体   繁体   中英

Get the MS Access source database of linked tables with Python

After searching a lot on this subject, I ask for your guidance !

With Python , I have to get to multiple Access database and extract information about the content of those database (name of table, type of table, source if it's a linked table ...).

I started by using pyodbc but when I wanted to access to the table MSysObjects that contains all the data I wanted but I had an access authorization problem (" Can not read records No read permissions on "\\ xa0MSysObjects \\ xa0 ").

After some search, I found few code lines to execute in the Access DB to authorize such request. But it needed to be launch from every Access DB because of some function only usable on an Access DB.

So I decided to use win32com to see if it had some solution for that. Sadly, it didn't. I had the exact same error.

Finally it seem to that there's only few solution :

  1. Find a way to put the few lines who give the authorization unto the database (maybe directly import by Python or by making Python importing it from a specific Access database) then execute it.
  2. Find a way to get the information needed (here, the source database of the linked tables) from another way than MSysObjects.
  3. Find a way to update the authorization directly from Python with a SQL request.

I hope I was understandable ! If you have an answer for one of the solution I thinked about or even a whole other solution, I will be really thankfull !

Best regards to all of you !

If you are OK with a non-Python solution, I would think VBA is the best tool fo rthis kind of job.

Private Sub Command1_Click()

Dim db As DAO.Database, tbl As DAO.TableDef
Dim f As DAO.Field
Set db = CurrentDb() ' Connect to current database

' Loop through each table in the database
For Each tbl In db.TableDefs
    Debug.Print "Table name: ", tbl.Name
    ' Loop throuth each field in the table
    For Each f In tbl.Fields
        Debug.Print "Field: ", f.Name
    Next f
Next tbl

End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM