Hello,
it gives me path that cannot accessed
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)
this method is currently not available for mobile platforms in MAUI. For MAUI programs, you can use FileSystem to set the database address.
#if ANDROID
public static string DatabasePath =>
Path.Combine(FileSystem.AppDataDirectory, DatabaseFilename);
#elif WINDOWS
public static string DatabasePath => Path.Combine(Environment.GetFolderPath(
Environment.SpecialFolder.LocalApplicationData), DatabaseFilename);
#endif
but folder is empty
The MAUI application on Windows will not release the file to the Local folder shown in the path, but will save it to C:\Users\username\AppData\Local\Packages\package_name\LocalCache\Local
In addition, for the initialization of Sqlite, the officially recommended method is to apply lazy loading. You don't need to call the Init method manually, the database will automatically trigger initialization the first time you use one of the methods.
The TodoItemDatabase uses asynchronous lazy initialization to delay initialization of the database until it's first accessed, with a simple Init method that gets called by each method in the class:
For MAUI programs using Sqlite, you can refer to the following official documentation and examples for more information.
Best Regards,
Alec Liu.
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.