In the App.xaml.cs
of my universal app I have opened an SQLConnection. I'm not closing the connection. So far it hasn't caused me trouble. But is it the right way, can we leave it like that?
If we are to close the connection (Dispose()
because I don’t see a close function) where do we close? In the App_Closing
?
EDIT
This is how I'm opening the connection in App.xaml.cs
public static SQLiteConnection conn;
public void LoadDatabase()
{
conn = new SQLiteConnection( "JusWriteDB.db");
string sql = @"CREATE TABLE IF NOT EXISTS Folder (FolderCompletedStatus INTEGER, FolderPriority INTEGER, PenColor INTEGER, FolderText TEXT, FolderUUID TEXT PRIMARY KEY NOT NULL );";
using (var statement = conn.Prepare(sql))
{
try
{
statement.Step();
}
catch(Exception)
{
}
}
}
And where ever(in some other file) I need a to access this connection, to update table or insert. I access it through the public variable defined in App.xaml.cs
var db = App.conn;
string sql = "SELECT * from Folder Where FolderSyncStatus = 'Del'; ";
try
{
using (var statement = db.Prepare(sql))
{
while (statement.Step() == SQLiteResult.ROW)
{ // code
}
}
}
catch{}