I've already created an SQLite database with tables and inserted some records in it. I have it stored locally in some folder. The thing I'm trying to do is to add that SQLite file into my Xamarin project so I can read records out of it. I didn't use SQLite-net-pcl nugget package since I only need this database to read some records out of it from a single table for testing a framework on prototype app.
I've tried to follow this guide:Use a local database in Xamarin but I don't know how to add the database into the assets and I just can't find any other solution online.
I've tried adding the database file into assets but I get to this and don't know how to continue with import. Current assets (image)
Edit: I've managed to add the prototype.db file to the root of the Android project (hopefully correctly) and now I'm having issues with establishing connection to that database so I can perform queries. : Pic of the database position in project. I've also created the interface in the C# project and a class for implementing that interface in Android project. I'm not sure if I'm doing all the necessary steps that are required to connect the database and Xamarin project.
IDatabaseConnection Interface snippet:
using System;
using System.Collections.Generic;
using System.Text;
using SQLite;
namespace Qooharitsa_Prototype_App.Connections
{
public interface IDatabaseConnection
{
SQLiteAsyncConnection Connection();
}
}
DatabaseConnection Class snippet:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Qooharitsa_Prototype_App.Connections;
using Qooharitsa_Prototype_App.Droid;
using SQLite;
using Xamarin.Forms;
[assembly: Dependency(typeof(DatabaseConnection))]
namespace Qooharitsa_Prototype_App.Droid
{
class DatabaseConnection : IDatabaseConnection
{
public SQLiteAsyncConnection Connection()
{
var documentsPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments);
var path = Path.Combine(documentsPath, "prototype.db");
return new SQLiteAsyncConnection(path);
}
}
}
How do I check if the connection to the database has been established?