1

I have looked at the few topics on this and tried the various proposed solutions (here for instance) but still I can't open my sqlite database.

It used to work smoothly but recently (I can't pinpoint when) I got the error:

Sqlite3, OperationalError: unable to open database file

Current set-up: the database is on an external hardrive connected to a mac mini via USB. I use a macbook pro to connect to this mac mini "server" via Ethernet. From my macbook pro, the following code returns the error:

import sqlite3 as sq3
import os

filename = '/Volumes/AGCM_DB/Database/AGCM.db'
conn = sq3.connect(filename)

What I tried:

  • running the code directly from the mac mini works fine

  • if I copy/paste the database onto my macbook pro, running the code works fine.

  • there is plenty of space available on the external harddrive, macbookpro and mac mini

  • from my macbook pro, I ran

    print(os.path.exists(filename))

which returns True so my macbook pro "sees" the file on the external harddrive via the mac mini.

I checked the permissions on the folder Database and on the file AGCM.db and my macbook pro has read&write.

My guess is that I am missing some permissionning somewhere (but where?).

Mac Mini: OS High Sierra Macbook pro: OS Big Sur

EDIT: I did another test of reading a ".csv" file and get an error "Operation not permitted" So this tells me I have a permission issue and it is not an sqlite issue

Hotone
  • 431
  • 3
  • 18
  • How is the macbookpro accessing the db file? How is it mounted? I'm a little confused with this. – ewokx May 07 '21 at 07:38
  • The macbook is connected to my local network via Ethernet cable and so is the mac mini. The harddrive is connected to the mac mini via USB cable – Hotone May 07 '21 at 07:56
  • Right, but how is the macbook pro accessing the file on the external hdd that's connected to the mac mini? – ewokx May 07 '21 at 07:57
  • on the mac mini Sharing menu, I checked Screen Sharing/ File Sharing with Read&Write (Shared Folders are the mac mini and the external harddrive) – Hotone May 07 '21 at 08:30
  • yes, but that only sets up file sharing. What path do you use on your macbook pro to access that fileshare? – ewokx May 07 '21 at 08:37
  • Ah, I use: filename = '/Volumes/AGCM_DB/Database/AGCM.db' AGCM_DB is the name of the external harddrive – Hotone May 07 '21 at 08:38
  • I just saw that the external harddrive is FAT32 instead of Mac OS Ext. J. No idea why this changed. Would reformating the disk to MacOS extended Journal fix this? – Hotone May 07 '21 at 08:56
  • I would try opening the database from another tool (e.g. the command line `sqlite3` tool, or any other SQLite capable app) and make sure that the file can be opened at all, to separate and programmatic issues from the (a) can the OS get to the file in question; and (b) is the file a valid SQLite3 database. – Rob May 07 '21 at 10:58
  • I will create a new topic as this is a permission issue and not related to sqlite as I initially thought For instance I can get the list of directories from os.listdir('/Volumes/') and AGCM_DB dir is listed there, but I get a permission denied with os.listdir('/Volumes/AGCM_DB/') – Hotone May 07 '21 at 11:18
  • 1
    @Hotone Even if you have/do get this working, it is not recommended to have an SQLite process access the database file across a network. See, for instance, [How to Corrupt](https://www.sqlite.org/howtocorrupt.html), in particular section 2, _File Locking Problems_. – TripeHound May 07 '21 at 11:55

1 Answers1

0

Ok I figured this out by trying do a simple copy/paste of a file from the macbook pro command line into the external drive

cp <source> <destination>

and it worked. So the permissioning was missing from my python editor: I gave full disk access to PyCharm on the macbook pro and now I get the desired list of directories in the external harddrive and access to the db on it as well.

Hotone
  • 431
  • 3
  • 18