[GIS] MS SQL Layer – Invalid Layer Error when Attempting to Load a Table

connectionqgissql server

I have a table called [stg].[Stops] in SQL Server that I would like to load in QGIS for data analysis. This is the first time I use the MSSQL Server connection option in QGIS. Unfortunately, even though QGIS recognizes the table and its geography data type. When I attempt to connect, I get an invalid layer error.

Here is a screenshot of the menu:

enter image description here

and here is the error:

2017-01-25T11:07:37 1 dbname='TK463' host=******* srid=4326
type=Point table="stg"."Stops" (GEOM) sql= is an invalid layer – not
loaded

What could possible cause that?

Best Answer

Posting DPSSpatial's comment as an answer:

Check you have a primary key field or a unique OBJECTID or ROWNUM field.

You can add this to a view by:

ROW_NUMBER() OVER(ORDER BY label ASC) AS ID#

where label is any column you choose.

Related Question