I am using an Android tablet with a Xamarin/C# application. With this tablet I am trying to access an SQLite database that resides on my Windows 10 machine. I opted to use the USB/Android vs the Android emulator, and the application still resides on the Windows 10 machine. It seems irrelevant, but I've also tried mapping a drive, sharing the folder, and creating a network connection. Project References
This is the code:
using Microsoft.Data.Sqlite;
using System;
using System.Windows.Input;
using Xamarin.Essentials;
using Xamarin.Forms;
namespace CicoAndroid { public partial class MainPage : ContentPage { public ICommand TapCommand => new Command(async (url) => await Launcher.OpenAsync(url)); private readonly string db1 = @"Data Source=\LAPTOP-FJUIC9RR\db\db.sqlite"; public MainPage() { InitializeComponent(); }
private void LoginClicked(object sender, EventArgs e)
{
int rows;
try
{
Console.WriteLine("DB1: " + db1);
SqliteConnection conn = new SqliteConnection(db1);
conn.Open(); ***This is the line that is throwing the exception.***
using (SqliteCommand cmd = conn.CreateCommand())
{
cmd.CommandText = "SELECT COUNT(*) FROM [tblUsers] WHERE USERNAME = 'someUser'";
rows = (int)cmd.ExecuteScalar();
Console.WriteLine("ROWS: " + rows);
cmd.Dispose();
}
conn.Dispose();
}
catch (Exception ex)
{
lblAuth.Text = "FUL: a.c.us" + Environment.NewLine + ex.ToString();
return;
}
I am very very new to Xamarin and C#, and I've tried tens of variations with the code and NuGet SQLite packages. Any help will be greatly appreciated.
Thank you