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

Even Rouault even.rouault at spatialys.com
Mon Jun 10 10:34:04 PDT 2019


On lundi 10 juin 2019 10:19:26 CEST jkellio2 wrote:
> Just in case anyone was curious. The issue here was in the way I was reading
> the result set layer the first time. I only read 1 feature (as that was all
> I was interested in). Evidently that leaves the result set in a busy state.
> I needed to either read the entire layer, i.e.
> 
>       OSGeo.OGR.Feature fea = layer.GetNextFeature();
>       while ( fea != null )
>       {
>         s = fea.GetFieldAsString( "name" );
>         layer.GetNextFeature();
>       }
> 
> Or I needed to reset the layer after reading, i.e.
> 
>       OSGeo.OGR.Feature fea = layer.GetNextFeature();
>       if ( fea != null )
>       {
>         s = fea.GetFieldAsString( "name" );
>       }
>       layer.ResetReading();
> 
> Once I did this I was able to write to the database the second time.

Ah, I missed that. Actually layer.ResetReading() is probably not enough and 
leaks memory.

Layers acquired with layer = ogrDataSource.ExecuteSQL() must be explicitly 
deallocated with
ogrDataSource.ReleaseResultSet(layer)

Even

-- 
Spatialys - Geospatial professional services
http://www.spatialys.com


More information about the gdal-dev mailing list