QTAgent32 holding file open
Posted: Tue 03 Jan 2012 14:46
In using VS2010/.Net 4.0 unit testing, a call to CreateDatabase() during a unit test results in QTAgent32.exe (the VS Test Executor) holding the resulting db file open. Explicitly calling the Dispose method on the DataContext at the end of the test does not cause the file handle to be disposed.
The only workaround I have found is to either restart VS altogether or use TaskManager to kill the QTAgent32.exe process, which will restart itself automatically (without the open file handle). Not a very elegant solution, methinks.
The only workaround I have found is to either restart VS altogether or use TaskManager to kill the QTAgent32.exe process, which will restart itself automatically (without the open file handle). Not a very elegant solution, methinks.
Code: Select all
public DBDataContext CreateContext(string path, bool failIfMissing)
{
SQLiteConnectionStringBuilder sb = new SQLiteConnectionStringBuilder();
sb["Data Source"] = path;
sb["FailIfMissing"] = failIfMissing;
string connectionString = sb.ToString();
DBDataContext db = new DBDataContext(connectionString);
if (!db.DatabaseExists())
{
db.CreateDatabase();
}
return (db);
}
[TestMethod]
public void CreateDb()
{
DBDataContext db = null;
string path = @"E:\DBTest\DBTest.db";
File.Delete(path);
try
{
db = CreateContext(path, /*failIfMissing*/false);
Assert.IsTrue(db.Draws.Count() == 0);
Draw newDraw = new Draw();
.....
db.Draws.InsertOnSubmit(newDraw);
db.SubmitChanges();
Assert.IsTrue(db.Draws.Count() == 1);
}
finally
{
if (db != null)
{
db.Dispose();
}
}
}