Unable to open database file
Posted: Tue 16 Apr 2013 20:23
The bug related to "Unable to open database file" exception when opening several connections in the LinqConnect for Metro edition was not fixed in 4.1.184 07-Feb-13 release. This code runs the first two times but after that it will give the "Unable to open database file". I am using direct calls because this is much faster than the linq to sql method when running in a transaction. I can load 100000 this way in minutes.
using (SQLiteConnection sqliteconnection = new SQLiteConnection("Data Source = database.db3; Version=3"))
{
sqliteconnection.Error += new SQLiteConnection.SQLiteErrorEventHandler(SQLiteError); ;
sqliteconnection.Open();
using (SQLiteTransaction sqlitetransaction = sqliteconnection.BeginTransaction())
{
SQLiteCommand command = sqliteconnection.CreateCommand();
try
{
command.CommandText = AttributeHelper.CreateInsertWithParameter<T1>(dc, ref command, add_items[0]);
command.Prepare();
foreach (var add_item in add_items)
{
AttributeHelper.SetParameters<T1>(dc, ref command, add_item);
command.ExecuteNonQuery();
sqlitetransaction.Commit();
}
catch
{
if (sqlitetransaction != null)
{
sqlitetransaction.Rollback();
}
}
if (sqliteconnection.State != ConnectionState.Closed)
{
sqliteconnection.Close();
if (sqliteconnection != null)
{
sqliteconnection.Dispose();
}
if (sqlitetransaction != null)
{
sqlitetransaction.Dispose();
}
if (command != null)
{
command.Dispose();
}
}
}
}
}
}
using (SQLiteConnection sqliteconnection = new SQLiteConnection("Data Source = database.db3; Version=3"))
{
sqliteconnection.Error += new SQLiteConnection.SQLiteErrorEventHandler(SQLiteError); ;
sqliteconnection.Open();
using (SQLiteTransaction sqlitetransaction = sqliteconnection.BeginTransaction())
{
SQLiteCommand command = sqliteconnection.CreateCommand();
try
{
command.CommandText = AttributeHelper.CreateInsertWithParameter<T1>(dc, ref command, add_items[0]);
command.Prepare();
foreach (var add_item in add_items)
{
AttributeHelper.SetParameters<T1>(dc, ref command, add_item);
command.ExecuteNonQuery();
sqlitetransaction.Commit();
}
catch
{
if (sqlitetransaction != null)
{
sqlitetransaction.Rollback();
}
}
if (sqliteconnection.State != ConnectionState.Closed)
{
sqliteconnection.Close();
if (sqliteconnection != null)
{
sqliteconnection.Dispose();
}
if (sqlitetransaction != null)
{
sqlitetransaction.Dispose();
}
if (command != null)
{
command.Dispose();
}
}
}
}
}
}