'Flutter Windows C: drive permission problem (using path_provider and SQFLite)

I am using the path_provider package along with SQFLite for a flutter app which is intended for Android and Windows platforms. I intend to use the ApplicationDocumentsDirectory for storing the database as it is available on all available platforms.

Future<Database?> _openDb() async {
    var dbDir = await getApplicationDocumentsDirectory();
    var dbPath = join(dbDir.path, 'app.db');
    Database? dbToBeReturned;
    try {
      dbToBeReturned = await openDatabase(
        dbPath, 
        version: dbVersion,
        onCreate: _onCreateDatabase,
      );
    } on Exception catch (e) {
      print('Exception @@@@ $e');
      dbToBeReturned = null;
    } catch (x) {
      print('This happened ${x.toString()}');
    }

    return dbToBeReturned;
  }

But when i run the app on Windows 11 it produces the following exception:

Exception @@@@ SqfliteFfiException(sqlite_error: 14, , open_failed: SqliteException(14): bad parameter or other API misuse, 
bad parameter or other API misuse (code 21)}) 
DatabaseException(open_failed: SqliteException(14): 
bad parameter or other API misuse, 
bad parameter or other API misuse (code 21))

However, if i provide a path manually like var dbPath = join('D:\\somefolder', 'app.db'); it works if and only if i provide it a path other than C: drive. If i use any location that points to C: drive like ApplicationDocumentsDirectory, ApplicationSupportDirectory or TemporaryDirectory it produces the same exception. From all this, it seems that it may be a permission problem that prohibits the app to write to C: drive. But i am unable to find a solution.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source