drift icon indicating copy to clipboard operation
drift copied to clipboard

SqliteException(14):while opening the database, unable to open database file (code 14)

Open amit1172 opened this issue 1 year ago • 8 comments

this example/app : https://github.com/simolus3/drift/tree/develop/examples/app

in windows when i try to run it throws below error

flutter: SqliteException(14): while opening the database, unable to open database file, unable to open database file (code 14)

Got a stack frame from package:stack_trace, where a vm or web frame was expected. This can happen if FlutterError.demangleStackTrace was not set in an environment that propagates non-standard stack traces to the framework, such as during tests. 'package:flutter/src/foundation/stack_frame.dart': Failed assertion: line 195 pos 7: 'line != '===== asynchronous gap ===========================''

The relevant error-causing widget was: HomePage HomePage:file:///C:/Users/AMIT/Downloads/simolus3%20drift%20develop%20examples-app/lib/main.dart:19:35

can some one help resolve this error ?

Thanks.

amit1172 avatar Apr 25 '24 13:04 amit1172

Facing the same issue on IOS

ustaadumar avatar Sep 03 '24 05:09 ustaadumar

We now include this to improve the stack trace situation:

https://github.com/simolus3/drift/blob/d3fa373c7f0260431d3ab04c5a91a8577b0997cc/examples/app/lib/main.dart#L10-L14

That doesn't fix the original error, but does adding that help to figure out where it's coming from? sqlite error code 14 sounds like the path to the database is inaccessible, but without further information it's hard to say why.

simolus3 avatar Sep 03 '24 19:09 simolus3

I encountered an issue while using aws storage_s3 (through amplify_storage_s3_dart), which transitively uses drift. I'm getting the following exception: .Non-fatal Exception: io.flutter.plugins.firebase.crashlytics.FlutterError: SqliteException(14): while opening the database, unable to open database file, unable to open database file (code 14) at Sqlite3Implementation.open(sqlite3.dart:62) at FfiSqlite3.open(implementation.dart:33) at _NativeDelegate.openDatabase(native.dart:306) at Sqlite3Delegate.open(database.dart:79) at DelegatedDatabase.ensureOpen.<fn>(engines.dart:431) at _AsyncCompleter.complete(dart:async) at DriftCommunication.request(communication.dart:113) at _RemoteQueryExecutor.ensureOpen(client_impl.dart:157) at LazyDatabase.ensureOpen.<fn>(lazy_database.dart:61) at DatabaseConnectionUser.doWhenOpened.<fn>(connection_user.dart:162) at SimpleSelectStatement._mapResponse(select.dart:90) at _MappedSelectable._mapResults(query.dart:291) at StorageS3Service.abortIncompleteMultipartUploads(storage_s3_service_impl.dart:595)

Could you please assist in diagnosing this issue? Are there any known solutions or configuration recommendations that might help resolve this error?

Thank you!

nazarcybulskij avatar Oct 31 '24 12:10 nazarcybulskij

Hi, Any news about this ?

I am facing the same issue : 1-Everything goes great with the example in the doc

2-When trying on a real iOS device, I receive the same error :

SqliteException (14): while executing statement, unable to open database: /private/var/mobile/Containers/Shared/AppGroup/XXX/File Provider Storage/Downloads/test.db, unable to open database file (code 14)
Causing statement: VACUUM INTO ?, parameters: /private/var/mobile/Containers/Shared/AppGroup/XXX/File Provider Storage/Downloads/test.db

Could it be related to device permission ?

Thanks !

ad-angelo avatar Aug 22 '25 19:08 ad-angelo

Could you check whether the directory you're copying the database into exists?

simolus3 avatar Aug 23 '25 07:08 simolus3

Hi @simolus3,

Thank you for the feedback (and the great job for this package !)

I take the example script as is. So this returntrue : https://github.com/simolus3/drift/blob/43e8b90ded952f1876edfab0f7a5e832975d1fda/examples/app/lib/screens/backup/supported.dart#L81-L85

But in fact Directory(file.absolute.path).exists() return false

ad-angelo avatar Aug 23 '25 08:08 ad-angelo

I've noticed that when I do:

final choosenDirectory = await FilePicker.platform.getDirectoryPath();
final file = File(p.join(choosenDirectory!, 'test.db'));

await file.create();

I get a PathAccessException: Cannot create file, path = '/private/var/mobile/Containers/Shared/AppGroup/XXX/File Provider Storage/Downloads/test.db' (OS Error: Operation not permitted, errno = 1)

So I'm not sure this is related to Drift. I'll try another approach to save the file.

ad-angelo avatar Aug 23 '25 11:08 ad-angelo

Finally succeeded in exporting the database using the share_plus plugin ! I definitely think it's due to permission-related issues.

Fun fact : it's exactly what's written in the doc

Result :

// Vacuum the database into a temporary location.
final tempDir = await getTemporaryDirectory();
final tempFile = File(p.join(tempDir.path,'backup.db'));

// Make sure de file does not exist.
if (await tempFile.exists()) {
await tempFile.delete();
}

await ref.read(appDatabaseProvider).customStatement(
'VACUUM INTO ?',
[tempFile.path],
);

// Export the database file
final shareResult = await SharePlus.instance.share(
ShareParams(files: [XFile(tempFile.path)]),
);

await tempFile.delete();

ad-angelo avatar Aug 24 '25 11:08 ad-angelo