Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

version V4 to V5 Problem #1428

Open
saeedrasti opened this issue Feb 1, 2020 · 24 comments
Open

version V4 to V5 Problem #1428

saeedrasti opened this issue Feb 1, 2020 · 24 comments

Comments

@saeedrasti
Copy link

Can't open version 4 db file in LIteDB 5.

@maxkatz6
Copy link
Contributor

maxkatz6 commented Feb 1, 2020

@saeedrasti hi!
Can you provide more information?
Something like exception message and stacktrace or database file for minimal repro.

@saeedrasti
Copy link
Author

Error message
LiteDB.LiteException: 'File is not a valid LiteDB database format or contains a invalid password.'
while no set password !

@mbdavid
Copy link
Collaborator

mbdavid commented Feb 2, 2020

Are you using "upgrade=true" in your string connection? You can try use LiteDB.Studio also

@saeedrasti
Copy link
Author

saeedrasti commented Feb 2, 2020 via email

@saeedrasti
Copy link
Author

👍 Converted success , Thanks a lot.

@JensSchadron
Copy link
Contributor

I'm closing the issue then :)

@UweKeim
Copy link

UweKeim commented Feb 3, 2020

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.


Edit 1

I've further inspected:

The first call to LiteDatabase with Upgrade=true succeeds without any exception and creates two new files:

  1. "content-temp.db" with the same size as the original "content.db".
  2. "content-temp-log.db" with 0 bytes size.

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?


Edit 2

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)	

Edit 3

I've reverted back to 4.1.4. Everything works again, correctly, even my newly added LiteEngine.Upgrade call now returns immediately and correctly.

@mbdavid
Copy link
Collaborator

mbdavid commented Feb 3, 2020

@UweKeim, I'm checking this....

mbdavid added a commit that referenced this issue Feb 3, 2020
@mbdavid
Copy link
Collaborator

mbdavid commented Feb 3, 2020

@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?

@mbdavid mbdavid reopened this Feb 3, 2020
@UweKeim
Copy link

UweKeim commented Feb 4, 2020

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).

@UweKeim
Copy link

UweKeim commented Feb 4, 2020

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.


Edit 1

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. 🤔

@Pokis
Copy link

Pokis commented Feb 4, 2020

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

@mbdavid
Copy link
Collaborator

mbdavid commented Feb 4, 2020

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).

@Pokis
Copy link

Pokis commented Feb 4, 2020

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.

@JensSchadron
Copy link
Contributor

@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?

@Pokis
Copy link

Pokis commented Feb 5, 2020

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.

@mbdavid mbdavid removed the v5 label Feb 9, 2020
@GonzoKK
Copy link

GonzoKK commented Feb 21, 2020

Busy testing v5. Also encountering "process cannot access the file" exception, even with ConnectionType.Shared

Worked perfectly for months on 4.1.4...

image

@huanlin
Copy link

huanlin commented Apr 14, 2020

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.

@GonzoKK
Copy link

GonzoKK commented Apr 14, 2020

Note that in my case I did try Connection = ConnectionType.Shared

Unfortunately the exception stills occurs intermittently :(

Back to 4.1.4 for now...

@okarpov
Copy link

okarpov commented Apr 22, 2020

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" ))

@okarpov
Copy link

okarpov commented May 14, 2020

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

@okarpov
Copy link

okarpov commented May 23, 2020

still throws exception but another one (was fine on V4).

configuration is the following:

  • Windows Service uses the db file
  • IIS ASP.NET MVC uses the same db file

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)

@lbnascimento
Copy link
Contributor

@okarpov Could you try with v5.0.8? There were changes to the mutex access.

@okarpov
Copy link

okarpov commented May 25, 2020

@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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants