SQLite open error 14 and sandbox settings

I thought I would open a new thread for this issue since it is really a new issue.

I am getting the following error trying to open a SQLite database. It seems it might be the temporary files SQLite creates causing the error.

2020-07-14 07:16:30.695866-0500 GRDBTest[2129:66789] [logging-persist] cannot open file at line 44152 of [d250d085fa]

2020-07-14 07:16:30.695927-0500 GRDBTest[2129:66789] [logging-persist] os_unix.c:44152: (0) open(/Users/test/Desktop/TestGRDB.db3) - Undefined error: 0

Fatal error: 'try!' expression unexpectedly raised an error: SQLite error 14: unable to open database file: file

I am using Xcode 11 on macOS Catalina and have the following sandbox settings:

Also, I see the following post in the apple developers forum:

Sandbox and SQLite

You would think this just some setting I am missing but I have not been able to resolve this.

Also, get the same error using the SQLite.swift package.

Hello @Eagle442BR,

Since you are experiencing sandbox-related errors, it is important that you describe which kind of sandbox-related access your application needs, and which kind of file your application is opening.

Do you want your app to open any SQLite file on the disk? Or only documents created by your app? In this case, are you developing an NSDocument-based app where SQLite databases are embedded inside document bundles, or not? Or are you developing an application that opens a database embedded as a resource in your app (for example, a dictionary app)? Or are you developing an application that creates one unique, shared, database (for example, a Notes.app-like app)?

Do you understand why these pieces of information, as well as your intents, are needed in order to spot the origin your problem? One does not just tick random checkboxes in Xcode until errors go away (I swear I wish it were sufficient :sweat_smile:)

Besides, you wrote:

It seems it might be the temporary files SQLite creates causing the error.

SQLite uses temporary files indeed. Well, based on the context of your app, your growing knowledge of the macOS sandbox, and your reading of Apple documentation, does this sentence ring some bell to you?

For me, you are on the way to a real understanding of what's wrong. When you have taken the time to gather the required information, the picture will be much more clear, as well as the solution. Please come back with the needed information.

1 Like

Gwendal,

What I am after is the app to create the database at the users specified location that I would get from the Prefs for the app, using $HOME/Documents as a default. However, for my initial testing I want to be able to connect for read/write to a test SQLite DB on my desktop. So, it would not be bundled inside a document bundle.

I printed the temp directory while running the app which is
(witch is really /private)/var/folders/g4/ws52m6lx2776vmpkwvd0b8l00000gn/T/CHCS.GRDBTest/. Nothing gets created in this directory. The path permissions are all rwx for directories and other things write in the T directory (T for TEMP)

So, it does look like I need to add some permissions within Xcode.

Also, I have look at this link App Sandbox in Depth

At any rate it still escapes me how to fix... but I will look some more later today...

All right, thank you for the context! It's much more clear now :-)

I am no sandbox expert, but please follow my reasoning. Sandbox is all about restricting applications from accessing parts of the file system, right? You have already seen dialogs like "App X wants to access your Documents folder - Accept - Deny", right?

Checking "User Selected File" in Xcode applies to files explicitly created by the app, or explicitly selected by the user in an Open dialog box (likely with NSOpenPanel).

It won't let the app access random files on the desktop, unfortunately. A quick Google search leads me to this Stack Overflow answer: https://stackoverflow.com/questions/12153504/accessing-the-desktop-in-a-sandboxed-app

Reading this, I think you may want to change your strategy for your initial testing. Maybe just jump directly to NSDocument bundles, so that your app does not fight against the system sandbox.


Now this thread is not about GRDB. It is not about SQLite either. It is about macOS file system fundamentals. The system just won't let your app open a file. It does not matter that this is an SQLite file, or that you use GRDB. You could not even deal with plain text files, or jpeg images, do you see?

This forum is no longer the best place to discuss this topic. You'll find better and more focused answers, from more knowledgeable people, on StackOverflow, or the Apple Developer Forums.

The other topic of NSDocument-based applications that use GRDB is not very well discussed online, but you will find some hints with this Github search: https://github.com/groue/GRDB.swift/issues?q=NSDocument

You are on the right track. And we all know this is a lot of information to learn! MacOS file system is... not quite the same as on iOS. Once this beast has been tamed, you'll be able to use GRDB just as on iOS.

Gwendal,

Thanks, you have been very helpful. I came to the same conclusion. I think I will try an app that just writes a string to a file and using debug I might get to the root of the problem..

Thanks again.

Terms of Service

Privacy Policy

Cookie Policy