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

Unable to close the reader #318

Open
yarong-lifemap opened this issue Aug 11, 2024 · 3 comments
Open

Unable to close the reader #318

yarong-lifemap opened this issue Aug 11, 2024 · 3 comments

Comments

@yarong-lifemap
Copy link

We are trying to implement an auto-update of the database in a background task on a Web Service. However, we cannot find a way to close the reader (even when locked) so that the database file can be replaced with a new one. Any thoughts?

@oschwald
Copy link
Member

There is a Dispose method that will call Dispose on the underlying MemoryMappedFile. I don't know if this is sufficient for your use case or not.

On a POSIX system, you should be able to atomically replace the file while the database is open, which is what I would recommend. I don't know offhand if this will work as expected on Windows.

@yarong-lifemap
Copy link
Author

Hi @oschwald . Thank you for getting back me so quickly.

I tried dispose and then replacing the file with the new version. However, the file was still locked and the move operation failed. This could also be an Azure / IIS file locking issue.

I'll try to work with multiple files instead for now.

@oschwald
Copy link
Member

Another option is to use the memory mode rather than the memory-mapped one. This will load the file into memory rather than mapping the file. You can do this with something like new DatabaseReader(dbFile, FileAccessMode.Memory).

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

No branches or pull requests

2 participants