Can't open version 4 db file in LIteDB 5.
@saeedrasti hi!
Can you provide more information?
Something like exception message and stacktrace or database file for minimal repro.
Error message
LiteDB.LiteException: 'File is not a valid LiteDB database format or contains a invalid password.'
while no set password !
Are you using "upgrade=true" in your string connection? You can try use LiteDB.Studio also
No , I’m checking now .
On Sun, Feb 2, 2020 at 15:56 Mauricio David notifications@github.com
wrote:
Are you using "upgrade=true" in your string connection? You can try use
LiteDB.Studio also—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/mbdavid/LiteDB/issues/1428?email_source=notifications&email_token=AE4J7UYUBWKX3EGZTHHIOVDRA23XNA5CNFSM4KOVJY7KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEKRVSTY#issuecomment-581130575,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AE4J7U36UM3AKCW37RVLZD3RA23XNANCNFSM4KOVJY7A
.
👍 Converted success , Thanks a lot.
I'm closing the issue then :)
Even after using Upgrade=true, this fails on my machine:
System.IO.IOException
-----------------
Der Prozess kann nicht auf die Datei "C:\MyFolder\content.db" zugreifen, da sie von einem anderen Prozess verwendet wird.
-----------------
bei System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
bei System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
bei System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
bei LiteDB.Engine.FileStreamFactory.GetStream(Boolean canWrite, Boolean sequencial)
bei System.Lazy`1.CreateValue()
bei System.Lazy`1.LazyInitValue()
bei LiteDB.Engine.DiskService..ctor(EngineSettings settings, Int32 memorySegmentSize)
bei LiteDB.Engine.LiteEngine..ctor(EngineSettings settings)
bei LiteDB.ConnectionString.CreateEngine()
bei LiteDB.LiteDatabase..ctor(ConnectionString connectionString, BsonMapper mapper)
Translated to English the error message reads something like:
The process cannot access the file '...' because it is being used by another process.
Any idea what might cause this?
I've ensured that no other thread holds any LiteDatabase instance.
I've further inspected:
The first call to LiteDatabase with Upgrade=true succeeds without any exception and creates two new files:
The original "content.db" file remains untouched/unchanged.
The next time I use LiteDatabase, this time without the Upgrade=true, the above error occurs.
Maybe I misunderstand how the upgrade is intended to work?
Even when trying to use LiteEngine.Upgrade(filePath) I get the same result.
After digging further, I discovered that a call to LiteEngine.Upgrade(filePath) simply does not return to my calling code.
Since I'm doing this in a ThreadPool thread, I added lock statements, only to see that following calls stall, since the original call to call to LiteEngine.Upgrade(filePath) did not return yet.
Manually breaking in debugger and switching to the originally thread, I see that the Upgrade call hangs here:
mscorlib.dll!System.Threading.ManualResetEventSlim.Wait(int millisecondsTimeout, System.Threading.CancellationToken cancellationToken)
LiteDB.dll!LiteDB.Engine.DiskWriterQueue.Wait()
LiteDB.dll!LiteDB.Engine.WalIndexService.Checkpoint(bool soft)
LiteDB.dll!LiteDB.Engine.LiteEngine.Upgrade(string filename, string password)
I've reverted back to 4.1.4. Everything works again, correctly, even my newly added LiteEngine.Upgrade call now returns immediately and correctly.
@UweKeim, I'm checking this....
@UweKeim, I'm try to simulate your problem but I didn't get this error. Can you fork and write how did you get the error?
Thank you very much, Mauricio. I'll try to build a proof-of-concept and hope to be able to isolate the erroneous behaviour (in hope that this is not something specific to my development machine).
Okay, I've created a simple .NET 4.8 console application:
internal static class Program
{
private static void Main()
{
var path = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location),
@"content.db");
LiteEngine.Upgrade(path);
Console.WriteLine(@"Finished.");
}
}
Here, the error does _not_ occur. So it must be something inside my "real" application.
Will investigate further now.
I've even tried it in a background thread:
var path = Path.Combine(
Path.GetDirectoryName(Assembly.GetEntryAssembly().Location),
@"content.db");
var e = new AutoResetEvent(false);
var did = false;
ThreadPool.QueueUserWorkItem(
delegate
{
did = LiteEngine.Upgrade(path);
e.Set();
});
e.WaitOne();
Console.WriteLine($@"Converted?: {did}.");
Still succeeds, though. 🤔
have same issue, lots of tests started failing with this error upon upgrade. How the test looks:
var someData = new Data[3]{data1, data2, data3};
using (var connection = new LiteDatabase(databaseName))
{
connection.DropCollection(nameof(Data));
}
var db = new LiteDatabase(connectionString);<--- throws exception. underneath
connection string is simple c:/path/path/dbfilename.db
Hi @Pokis, is not missing "upgrade=true" in connection string (if you want upgrade from v4 database).
I added this options in connection string because check for upgrade have a cost (need open datafile, check some bytes and close datafile).
These tests create new database, not upgrade it, thus it's not used in here. I've applied it in necessary places.
This prompts the same error of:
The process cannot access the file 'C:\src\xxxxx.db' because it is being used by another process.
@Pokis Just a wild guess, but is it possible that your antivirus/antimalware software is keeping a look on it? Have you tried excluding the folder?
checked just in case, disabling antivirus does not help. But it does work with version 4.1.4 just fine (same tests in same solution). Another note, get operations works fine, while store operations throw the mentioned exception.
Busy testing v5. Also encountering "process cannot access the file" exception, even with ConnectionType.Shared
Worked perfectly for months on 4.1.4...

FYI, after I upgrade LiteDB from v4 to v5, I encountered the same exception saying "process cannot access the file." Then I added "Connection=Shared" to connection strings, as below:
var repo = new LiteRepository("Filename=database.db;Connection=Shared");
The exception was gone now.
Note that in my case I did try Connection = ConnectionType.Shared
Unfortunately the exception stills occurs intermittently :(
Back to 4.1.4 for now...
Can't open version 4 db file in LIteDB 5.
works for me with 5.0.7
using (var ldb = new LiteDB.LiteDatabase("Filename="+System.IO.Path.Combine(Models.HDDQueue._path, "HDDSLite.db")+"; Upgrade=true" ))
using new LiteDB.LiteDatabase("Filename=HDDSLite.db; Upgrade=true; Connection=shared")
all the time still throws "The process cannot access the file '...' because it is being used by another process"
will try without the Upgrade=true;
using on windows server 2016 under IIS + ASP.NET MVC 5 in asynchronouse and sync+async requests
still throws exception but another one (was fine on V4).
configuration is the following:
first upgrade connection string
using (var ldb = new LiteDB.LiteDatabase("Filename=" + System.IO.Path.Combine(Models.HDDQueue._path, "HDDSLite.db") + "; Upgrade=true"))
then:
using (var ldb = new LiteDB.LiteDatabase("Filename=" + System.IO.Path.Combine(Models.HDDQueue._path, "HDDSLite.db") + "; Connection=shared"))
System.UnauthorizedAccessException: Access to the path '9E9EEB467E9A7CE2A3A4DD28ECF140E4D1AE0738.Mutex' is denied.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.Threading.Mutex.MutexTryCodeHelper.MutexTryCode(Object userData)
at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
at System.Threading.Mutex.CreateMutexWithGuaranteedCleanup(Boolean initiallyOwned, String name, Boolean& createdNew, SECURITY_ATTRIBUTES secAttrs)
at System.Threading.Mutex..ctor(Boolean initiallyOwned, String name, Boolean& createdNew, MutexSecurity mutexSecurity)
at System.Threading.Mutex..ctor(Boolean initiallyOwned, String name)
at LiteDB.SharedEngine..ctor(EngineSettings settings)
at LiteDB.ConnectionString.CreateEngine()
at LiteDB.LiteDatabase..ctor(ConnectionString connectionString, BsonMapper mapper)
@okarpov Could you try with v5.0.8? There were changes to the mutex access.
@okarpov Could you try with v5.0.8? There were changes to the mutex access.
seems fine
will give it a little bit more time to test
thx!
Most helpful comment
Are you using "upgrade=true" in your string connection? You can try use LiteDB.Studio also