my first time posting.
I made a console application that run in the background, it was written in C# and I'm using sqlite3 to store its information. It's running under mono but I'm getting unable to open database file after running fine for a few days. Restart the application solve the issue but it will give me the same error after few days.
I suspect it was the connection not getting dispose after close so I added dispose after the connection.close() but still getting the same error. I also did some search and find out this thread have similar problem, I did what he said but still getting same error.
Any help will be appreciated.
Sorry for bad english
UPDATE : My Code
private static void ExecuteNonQuery(string query)
{
if (isrunningundermono == true)
{
SqliteConnection sqlcon = new SqliteConnection(ConfigurationManager.AppSettings["connectionString"]);
SqliteCommand sqlcmd;
sqlcon.Open();
sqlcmd = sqlcon.CreateCommand();
sqlcmd.CommandText = query;
sqlcmd.ExecuteNonQuery();
sqlcon.Close();
sqlcmd.Dispose();
sqlcon.Dispose();
}
else
{
SQLiteConnection sqlcon = new SQLiteConnection(ConfigurationManager.AppSettings["connectionString"]);
SQLiteCommand sqlcmd;
sqlcon.Open();
sqlcmd = sqlcon.CreateCommand();
sqlcmd.CommandText = query;
sqlcmd.ExecuteNonQuery();
sqlcon.Close();
sqlcmd.Dispose();
sqlcon.Dispose();
}
}
private static int ExecuteScalar(string query)
{
if (isrunningundermono == true)
{
SqliteConnection sqlcon = new SqliteConnection(ConfigurationManager.AppSettings["connectionString"]);
SqliteCommand sqlcmd;
sqlcon.Open();
sqlcmd = sqlcon.CreateCommand();
sqlcmd.CommandText = query;
int total = Convert.ToInt32(sqlcmd.ExecuteScalar());
sqlcon.Close();
sqlcmd.Dispose();
sqlcon.Dispose();
return total;
}
else
{
SQLiteConnection sqlcon = new SQLiteConnection(ConfigurationManager.AppSettings["connectionString"]);
SQLiteCommand sqlcmd;
sqlcon.Open();
sqlcmd = sqlcon.CreateCommand();
sqlcmd.CommandText = query;
int total = Convert.ToInt32(sqlcmd.ExecuteScalar());
sqlcon.Close();
sqlcmd.Dispose();
sqlcon.Dispose();
return total;
}
}
private static DataTable ExecuteDataSet(string query)
{
if (isrunningundermono == true)
{
DataTable dt = new DataTable();
SqliteConnection sqlcon = new SqliteConnection(ConfigurationManager.AppSettings["connectionString"]);
SqliteCommand sqlcmd = new SqliteCommand(sqlcon);
sqlcon.Open();
sqlcmd.CommandText = query;
SqliteDataReader reader = sqlcmd.ExecuteReader();
dt.Load(reader);
reader.Close();
sqlcon.Close();
sqlcmd.Dispose();
sqlcon.Dispose();
return dt;
}
else
{
DataTable dt = new DataTable();
SQLiteConnection sqlcon = new SQLiteConnection(ConfigurationManager.AppSettings["connectionString"]);
SQLiteCommand sqlcmd = new SQLiteCommand(sqlcon);
sqlcon.Open();
sqlcmd.CommandText = query;
SQLiteDataReader reader = sqlcmd.ExecuteReader();
dt.Load(reader);
reader.Close();
sqlcon.Close();
sqlcmd.Dispose();
sqlcon.Dispose();
return dt;
}
}
public static bool IsRunningOnMono()
{
return Type.GetType("Mono.Runtime") != null;
}