[gdal-dev] Getting database is locked error when writing to GeoPackage database.

Even Rouault even.rouault at spatialys.com
Wed Jun 5 05:47:25 PDT 2019

On mercredi 5 juin 2019 05:38:32 CEST jkellio2 wrote:
> I'm using the OGR/GDAL C# managaged API to write to a GeoPackage database
> and I keep running into a "database is locked" error when I try to sync the
> database to disk.  After much experimentation, this appears to only happen
> if I first open the GeoPackage to do a read, close the db (Dispose the
> DataSource), reopen db and attempt to write.  Web searches indicate that
> this error occurs if the GDAL and SQLite objects from the read are not
> disposed before attempting the write.  However, I think I'm disposing all
> the managed objects properly so I'm wondering if there is a call that I'm
> missing.

I'm pretty ignorant of C#, but I believe you may need to explicitly call the 
SWIG generated Dispose() method on the DataSource object. Pure C# garbage 
collection is probably not always sufficient.


Spatialys - Geospatial professional services

More information about the gdal-dev mailing list