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?

  • In QGIS 3.x the default data format is GeoPackage (which is a sqlite database with spatial extension in the background). A suppose you have not opened so far GeoPackage database but ESRI shape files, so there is a problem with the sqlite/spatialite installation. You should check weather sqlite is available. Several programs (even Windows) use sqlite, it happens that you have several version of sqlite.dll on your machine, and QGIS finds an incompatible version. Reordering the folders in PATH may help. Move QGIS folders to the beginning. – Zoltan Jul 23 '18 at 6:55
  • Thank you, Zoltan. It does seem like you have the right idea. Strange, that I have read as far as I have in the user manual and did not see, that it is possible to open and work with a shapefile and not have any geopackage open. I would think that's kind of an important concept... Anyway, may I ask you to clarify the last part? What PATH are you referring to? If QGIS doesn't create a geopackage with every new project, that must mean I have to create one myself, or import someone else's. How do I do that? – John A. Jul 23 '18 at 8:32
  • I see there was a folder added to the one I created to hold my data for the project. I did not put it there. It is called DEFAULT/PERMANENT/SQLITE. The PERMANENT folder has in it files called DEFAULT WIND, MYNAME, PROJ_EPSG, PROJ_INFO, PROJ_UNITS, VAR, and WIND. I have no idea what these files are - they have no file type extensions. Is one of these the database I'm trying to write to? Does PROJ mean "project" or "projection"? – John A. Jul 23 '18 at 8:53
  • I also see that every file in that directory has a size of only 1 kb, so I suppose none of them are databases. Also, the SQLITE folder is empty. I do not understand the purpose of this file structure... – John A. Jul 23 '18 at 9:31
  • Geopackage is a separate file format from shapefile. You can have a vector layer in either of these formats; they are completely unrelated. To create a geopackage, go to the Layer menu > Create Layer > New Geopackage Layer. Once you have a geopackage, you can add as many layers as you want to it. Unlike shapefiles, which have only one layer per shapefile. – csk Jul 30 '18 at 21:14

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.

  • Thank you so much for the explanation, csk. Yes, I absolutely wanted to know why I was running into the problem. Your explanation is very clear, and I understand what I need to do now. Much appreciated! – John A. Jul 31 '18 at 22:39
  • Happy to help. FYI, the geopackage format is supposedly much better than the shapefile format. Eg, no character limit on field names, one single file as opposed to multiple files, etc. That said, I still use shapefiles for pretty much everything. – csk Aug 1 '18 at 17:21

Well... this isn't an answer exactly, but I found a workaround that seems to do the trick for now. I still wish I knew why doing what I'm supposed to do doesn't yield the result it's supposed to as far as almost any function that involves writing to some mystery database. BUT --

After trying every other tool, I found one that works. And in the end it's just as effective. Not elegant, not proper, not efficient. But effective.

One of the Data Management tools in the Vector menu is "Split Vector Layer." I've done this now several dozen times. Honestly I don't know what the difference is between "Split Vector Layer" and "Create New Shapefile Layer" because if I could do the latter, the result I'd expect is exactly what I get with the Split tool.

I've been wanting to create a subset of the primary layer, so I select the features I want and split them. The source layer remains intact, the new layer contains just the selected items. (The tool is more versatile than that, but that's what I need it do do.) Imagine starting with a State layer but you want a separate layer for each county. This can do that, and each new layer contains all the fields of the parent layer.

In order to avoid confusion because of the default naming convention for the new layer, I go to the output folder from Windows Explorer and rename the new shapefile and its associated files.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.