Как правильно управлять SQLiteConnection, чтобы избежать исключения DatabaseConnectionException?
Я попытался установить некоторые флаги в конструкторе sqliteconnection и использовать оператор Using, но, похоже, он не работает
public class BaseDao
{
//[...] some static functions
static string Path = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "mysqlite.db3");
/// <summary>
/// Searches all records of the specified type
/// </summary>
/// <typeparam name="T">the Type to search</typeparam>
/// <returns>Returns a list of all records of the specified type</returns>
public static List<T> GetItems<T>() where T : BaseEntity, new()
{
List<T> items;
using (SQLiteConnection connection = new SQLiteConnection(Path, SQLiteOpenFlags.ReadWrite | SQLiteOpenFlags.Create | SQLiteOpenFlags.FullMutex, true))
{
try
{
items = connection.Query<T>("SELECT * FROM " + typeof(T).Name);
}
catch (Exception ex)
{
connection.Rollback();
throw ex;
}
finally
{
connection.Close();
}
}
return items;
}
(эти функции не вызываются потоком пользовательского интерфейса.)