pmikstacki / SliccDB

Light Embedded Graph Database for .net
MIT License
132 stars 14 forks source link

"System.IO.IOException" When CreateNode #5

Closed szlq closed 1 year ago

szlq commented 2 years ago

In the example, I don't see how to create a database that doesn't exist on the hard disk. So I write these codes (I want to create a new gdb file, instead of visiting a exsiting file, like @"..\..\..\data\sample"):

            var path = @"H:\AAAAATEMP\sample3";

            //delete the old gdb file
            if (File.Exists(path))
            {
                File.Delete(path);
            }

            //create a new gdb file
            var connection = new DatabaseConnection(path);

            var n0 = connection.CreateNode(
               new Dictionary<string, string>() { { "Name", "Ken" } },
               new HashSet<string>() { "Person" }
             );

But the 'CreateNode' throws an "System.IO.IOException".

I download the souce code and debug, and located the the place of error.

Finally, I think the reason is that:

  1. In the new DatabaseConnection(path), it will File.Create(filePath); , but I need to change it to File.Create(filePath).Close();
  2. In the connection.CreateNode(...), it will SaveDatabase()
  3. In the SaveDatabase(), it will File.WriteAllBytes(FilePath, bytes);, but at the moment, the file is occupied by File.Create(filePath);

I'm a beginner. I'm not very good at C#. I'm a little confused. I'm not sure whether I should revise it like File.Create(filePath).Close();, but it does work well when revising it.

Thanks.

pmikstacki commented 2 years ago

Hi, Thanks for interest in this project! I will have a look at it on the weekend and get back to you ASAP Kind Regards, Piotr Mikstacki

pmikstacki commented 1 year ago

clone of #12