Problem with StopEditingTable

Good morning everyone.
I’m developing software for editing polygonal shape files and I’m having a strange problem and I can’t figure out the cause. I use Visual Studio 2019 Community with language Vb.Net.
Basically my program allows you to draw polylines on the map and save them on a shapefile.
The program works perfectly without any problems for a few days, then suddenly, any operation on the shapefiles (adding a point, creating a shape, etc.)
it runs more and more slowly until it becomes unsustainable.
At this point, if I try to delete the .shp, .shx and .dbf files to have the program recreate them, these files are created but the table attributes in the .dbf file are not created and therefore the
program no longer works.
Uninstalling and reinstalling MapWinGis didn’t help, so I found myself forced to format the pc.
It worked for a few days but then the problem came back.
I’ve had this problem on 3 different PCs.

Here is a piece of code that I use to create the attributes of a shapefile after creating it:

1 if sfgrafo.StartEditingTable() Then
2 sfgrafo.EditAddField(“id”, FieldType.STRING_FIELD, 2, 50)
3 sfgrafo.EditAddField(“name”, FieldType.STRING_FIELD, 2, 50)
4 sfgrafo.StopEditingTable() <— Slow operation
5 End If

The code runs fine until line 3 (the 2 fields “id” and “name” are added) but
the “StopEditingTable” instruction is very slow and after execution the 2 fields are gone.

Does anyone know how I can fix this?
Thank you for your attention.

Roberto

Has anyone had the same problem? Sorry but I’m going crazy!!

Hello Roberto.

At first glance, here are some considerations:

  1. Check the return value for EditAddField to make sure it’s not -1 (see EditAddField)
  2. For a STRING field, the precision can (should?) be zero, so … (“name”, FieldType.STRING_FIELD, 0, 50)
  3. Did you pre-delete those fields, and you know they don’t already exist?
  4. It’s unclear whether you are trying to edit an existing table vs having just created a new table1. We would likely need to see more of the program context to have any suggestions as to why it seems to stop working after a few days
    Regards,

Jerry.

One other question:
5. Are you deleting the SHP, SHX, and DBF files while the program is running?

HI. Thanks for the reply. My application uses some supporting shape files. At startup I check if these shape files exist and if they don’t exist I create them. They are simple shape files with just one ‘id’ field. It has happened to me several times on different computers that while using my application, operations on the shape files (adding, editing and deleting) slowed down a lot. In all these cases I noticed that the block occurred on the ‘StopEditingTable’ command and the changes were not executed. By manually deleting the shape files, my application automatically recreates them but returns the error ‘StopEditingTable’ (Err. Table: Can’t create dbf file) when it tries to recreate the fields. In these cases it creates the dbf in the right path without any fields and also creates dbf files in the startup directory naming them with strange characters or with the name of the fields (E.g. id.dbf or adqdefdwqed.dbf etc.). This lasts for a few days or weeks or more and then a few times it goes away on its own. Other times I had to format the PC because reinstalling the OCX didn’t help. Has it ever happened to you? What could it depend on? Thank you for the support.

  1. EditAddField returns 1 and the numShape of the shapefiles increases by one;
  2. I realized I was using precision 2 so I’ll try (even if it always worked and suddenly it doesn’t work anymore);
  3. The fields are created only once during the creation of the shape file and then no more fields are added;
  4. If sf.StartEditingTable() then
    sf.EditAddField(“id”, FieldType.STRING_FIELD, 2, 50)
    sf.StopEditingTable()
    end if
  5. I create the shape files with the fields I need once and then I don’t touch them again except to add records.