QGIS Error – How to Fix “Unable to Open Database File” in QGIS 3.2.0

errorqgisqgis-3

I'm brand new to QGIS but 10+ years ago I was adept with ArcGIS. I installed 3.2.0 just a few days ago and all went well at first. I located/downloaded/imported the data I want and added a field to the table in each layer. I'm using Windows 10 Home v.1803, 64-bit. Now I want to create new layers using that new field. Screeching halt.

I can't create a new layer. I can't clip the layer. I can't filter the layer. I can't create anything else, apparently, because I keep getting some version of this error:

"Export to vector file failed. Error: Creation of data source failed
(OGR error: sqlite3_open(NC GeoRegions.gpkg) failed: unable to open
database file)"

I'm not sure what database it's trying to open, or I would check out its read-write permission. And anyway I can't believe the message is accurate. If QGIS cannot "open" a database, how in the world can it read that database to populate attribute tables? It makes no sense on its face.

What am I doing wrong?

Best Answer

The easy solution to your issue is to export using the shapefile format instead of the geopackage format.

See below if you want to know why you're having this issue.


Geopackage is a database format. In one geopackage, you can have many layers. This is different from the shapefile format. Each shapefile layer is a separate file (actually 3-6 files, but you probably already know that).

You must have an existing geopackage before you can add a layer to it. When you try to export as a geopackage layer, QGIS can't find a geopackage to add the layer to. That's why you're getting the error message "unable to open database."

You must create a geopackage before you can add layers to it.

To create a geopackage database, go to the Layer menu > Create Layer > New Geopackage Layer. In the window that pops up, next to click the "..." button next to Database. Choose the folder where you want to put your database and type in a name. Click Save, then click OK.

Now you have a geopackage with one empty table. You can now export layers to this geopackage.

Related Question