System.UnauthorizedAccessException when inserting
See original GitHub issueToday I found LiteDB and took some very basic tests:
- I’ve used the Basic example from www.litedb.org
- Put it into a 1000 loop.
What happens next will shock you 😉:
After several iterations (sometimes 28, sometimes 101, sometimes …) I get an exception:
System.UnauthorizedAccessException
Access to MyData-journal.db was denied.
This is the complete source code of my .NET 4.7 console application:
namespace TestNoSQL
{
using LiteDB;
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
// Basic example
public class Customer
{
public int Id { get; set; }
public string Name { get; set; }
public string[] Phones { get; set; }
public bool IsActive { get; set; }
}
internal static class Program
{
private static readonly string _path =
Path.GetDirectoryName(Assembly.GetEntryAssembly().Location).TrimEnd('\\') +
@"\MyData.db";
private static void Main(string[] args)
{
const int count = 1000;
var sw = new Stopwatch();
sw.Start();
for (var i = 0; i < count; ++i)
{
one();
}
sw.Stop();
Console.WriteLine($@"{count} times '{nameof(one)}' took. {sw.Elapsed}.");
}
private static void one()
{
// Open database (or create if not exits)
using (var db = new LiteDatabase(_path))
{
// Get customer collection
var customers = db.GetCollection<Customer>("customers");
// Create your new customer instance
var customer = new Customer
{
Name = "John Doe",
Phones = new string[] { "8000-0000", "9000-0000" },
IsActive = true
};
// Insert new customer document (Id will be auto-incremented)
customers.Insert(customer);
// Update a document inside a collection
customer.Name = "Joana Doe";
customers.Update(customer);
}
}
}
}
My question:
Is this a design limitation or am I doing something significantly wrong?
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Windows Service - UnauthorizedAccessException Error ...
InstallLog. An exception occurred during the Install phase. System. UnauthorizedAccessException: Attempted to perform an unauthorized operation.
Read more >UnauthorizedAccessException Class (System)
The exception that is thrown when the operating system denies access because of an I/O error or a specific type of security error....
Read more >Debugging System.UnauthorizedAccessException
Today, I want to introduce you to System.UnauthorizedAccessException. The exception is typically caused by an IO error, but other issues ...
Read more >Access to the path is denied.] after installing GUMU ...
How to resolve ERROR [System.UnauthorizedAccessException: Access to the path is denied.] after installing GUMU™ Extension.
Read more >System.UnauthorizedAccessException Issue : r/skyrimmods
Installing anything under Program Files can result in Windows UAC interfering in normal execution of SKSE, SKSE plugin mods and other modding ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Huge difference between Access and LiteDB 😄
LiteDB is 100% managed .NET code, runs in-process. Read access are optimized to re-use cached block pages, so disk access are reduced too.
One last addition, my comparison between MS Access and LiteDB:
This is based on the Basic example with the
Customer
class.I’ve also added a test based on this ticket in order to compare with an in-memory version of the LiteDB database file.