Database file locked error while reading chrome history c#
One solution is to copy the file to a temporary location and read it from there.
string source = @"C:\Users\{USERNAME}\AppData\Local\Google\Chrome\User Data\Default\History";string target = @"C:\Temp\History";if (File.Exists(target)){ File.Delete(target);}File.Copy(source, target);string cs = @"Data Source=" + target;string sql = "Select * From urls";using (SQLiteConnection c = new SQLiteConnection(cs)){ c.Open(); using (SQLiteCommand cmd = new SQLiteCommand(sql, c)) { using (SQLiteDataReader rdr = cmd.ExecuteReader()) { while (rdr.Read()) { Console.WriteLine(rdr[1].ToString()); } } }}
I've found chrome.exe will continue running, and holding the lock, despite exiting the browser as normal.
taskkill.exe /IM chrome.exe /F
This will shut down Chrome, with an added bonus of having a 'restore tabs' button upon restart by the user. Restore tabs is available because you killed forcefully.