[QGIS-Developer] Can I refresh PostGIS DB connection in pyqgis

Stefan Blumentrath Stefan.Blumentrath at nina.no
Thu May 31 04:00:10 PDT 2018


Dear devs,

When I try to load a layer from a PostGIS data source where the connection has timed out, is there a way in pyqgis (2.18) to refresh the connection programmatically like in DBmanager before loading the layer?

psycopg2 connections are no problem...

The following however:

# Add new layer
uri = QgsDataSourceURI()
uri.setConnection(host, port, db_name, user, password)
uri.setDataSource('', query, 'geom','', 'ID')
lyr = QgsVectorLayer(uri.uri(), layer_name, 'postgres')

gives me "No result buffer" error in PostGIS...

Thanks for any hint in advance.

Kind regards,
Stefan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20180531/07dbae97/attachment.html>


More information about the QGIS-Developer mailing list