Connecting SQLite in MAUI
How to connect the database without absolute path? If with it, the program works only on the computer, it does not run on the phone. I need both desktop and mobile to work.
5 Replies
.NET MAUI local databases - .NET MAUI
.NET MAUI supports database-driven applications using the SQLite database engine, which makes it possible to load and save objects in shared code. This article describes how .NET MAUI applications can read and write data to a local SQLite database using SQLite-net
I created the database in DB Browser for SQLite. I added it to the project. On the basis of this I created the database context via EF Core through Reverse Engineering, and also created the database table models automatically. In this guide, and in the ones I found, it is done manually. They don't even use any Database Management System.
If you want a pre-existing database you'll have to deploy with your app. I believe then the path would still be
Path.Combine(FileSystem.AppDataDirectory, DatabaseFilename);
if it gets deployed correctly. Does the database already have data in it or are you just needing it to have tables created?