Unable to connect to database on Mac

I have an app that I’ve started coding on my PC but want to run on my mac. The code for connecting to the database is the same except I’ve changed to the appropriate mac path but now it won’t connect to the sqlite database that I have move to the macintosh. Ideas?

db = new SQLiteDatabase
db.DatabaseFile = new FolderItem("/Users/sharonD214/Desktop/Database/Gentracker.db")
try
  db.Connect
Catch e as DatabaseException
  MessageBox e.Message
end try

Not sure of the error you’re encountering, or if any is appearing? but try this code and let me know if it works.

db = new SQLiteDatabase
db.DatabaseFile = SpecialFolder.Desktop.Child("Database").Child("Gentracker.db")
try
  db.Connect
Catch e as DatabaseException
  MessageBox e.Message
end try

If an error appears, can you share the error to help in tracking down what is happening?

**If the database is encrypted, you will need to decrypt it first using the original software that created it, unless it was created in and encrypted by Xojo from the start. SQLite Encryption is different between languages/products.

Try this: var f as new folderitem("/Users/sharonD214/Desktop/Database/Gentracker.db",FolderItem.pathModes.Native)

I am getting the same error with your code. “unable to open the database file” The database is not encrypted.

Thanks
Sharon

Check the values of db.Exists and db.IsFolder. Easiest to do that in the debugger as you step past the .Connect.

db.exists is true isfolder is false

so strangely my code works fine on mac 10.13.6 but not on 12.1 Monterey?

OK. So explain what you mean by: it won’t connect to the sqlite database that I have moved to the macintosh.

I copied the SQLlite database and the XOJO binary to my macintosh. Now when I run the XOJO on my mac running Monterey it will not connect to the database

What I was after are what is the error message? What are the symptoms? Without this sort of information all we can do is guess.

the error message is "unable to open the database file”

Hmm, not too informative. Are you familiar with using Terminal? I’d be inclined to run the sqlite3.app CLI and see if that can open the db. Your Mac will already have a copy of that program. You run it in Terminal.

I have sqlite studio installed and can open the database just fine and run queries on it

Did you try using @Michael_Eckert 's change rather than @Matthew_Combatti 's ?

Try to give your app full disk access - as it may not be allowed to access the desktop without entitlement…

I tried both, they both give the same error

Thomas, not sure how to do that in debug mode

ok so I copied the binary file to my desktop and tried running it again. this time it asked me to give xojo access to the desktop folder and I clicked yes. It works fine now. There must be something in Monterey that prevents access to the desktop folder. Not sure why I didn’t get this prompt the first time I tried it.

Thanks all
Sharon

I am not sure if this is the same cause, but I think it is worth mentioning here. Once, I absentmindedly clicked “don’t allow” when the popup window for my app asked for permission to access the Documents folder (on MacOS Monterey). After that my app kept erroring whenever it tried to save a file in the Documents folder. Restarting the app didn’t help.

Eventually I discovered the solution. In System Preferences → Security & Privacy → Files and Folders, I needed to give my app access to the Documents folders. It seems that once you’ve made a choice, it is saved and it won’t prompt you again.

1 Like

The other thing I do in my app’s startup is to determine where I want to write the app’s logfile, and then try to open it for writing text. If that works, just close and continue, otherwise put up a modal dialog saying that the app could not initialise, and quit. That should hint the user.

1 Like