I've added 2 C# integration tests for an existing SQLite application. Each test creates a database file (using a Guid to guarantee uniqueness) and does a couple of operations on the database. The tests pass in isolation but fail if run one after the other. The second test fails at the point of attempting to create a new SQLiteConnection, with "unable to open database file".
I suspect SQLite's own temporary files are getting in the way. My question in summary is: can I do something to get SQLite to tidy up after itself properly at the end of a test ?
Some more details, just in case any of this is relevant:
I can see a number of files and folders in %TEMP% after the first test has completed, and before the second test attempts to create its database file:
Folder EAFBACB1-B978-419A-98B9-07258EB35C44.scratch
The presence of the temporary SQLite files is a red herring. The real problem with my code is a line within the MS MobileServiceSQLLiteStore wrapper that I'm calling:
MobileServiceClient.EnsureFileExists(dbPath);
This ultimately resolves to
if (!File.Exists(path)) File.Create(path);
As this Stack Overflow answer points out, File.Create() will leave the file locked. So my fix was to ensure the file empty, unlocked file existed beforehand:
if (File.Exists(path)) File.Delete(path);
File.Create(path).Close();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.