pmikstacki/SliccDB

"System.IO.IOException" When CreateNode

szlq opened this issue · 0 comments

szlq commented

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.