question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

System.UnauthorizedAccessException when inserting

See original GitHub issue

Today 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:closed
  • Created 6 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
mbdavidcommented, Oct 4, 2017

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.

1reaction
UweKeimcommented, Oct 3, 2017

One last addition, my comparison between MS Access and LiteDB:

Access             of 1000 WRITE iterations took 00:00:38.9010116.
LiteDB             of 1000 WRITE iterations took 00:00:02.0247147.
LiteDB (in-memory) of 1000 WRITE iterations took 00:00:00.1703879.

Access             of 1000 READ  iterations took 00:00:47.4544505.
LiteDB             of 1000 READ  iterations took 00:00:00.0133699.
LiteDB (in-memory) of 1000 READ  iterations took 00:00:00.0122957.

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found