[GIS] Import non spatial data into SQL Server using ogr2ogr

csvogr2ogrsql server

I am trying to import a CSV files in to SQL Server 2012 using ogr2ogr. The spatial data imports without any problems, but I cannot work out why the non spatial tables fail. I can import the data using other tools but it would be convenient if I could import everything using ogr2ogr so I can script it more easily.

My VRT file looks like this…

    <OGRVRTDataSource>
      <OGRVRTLayer name="test">
        <SrcDataSource relativeToVRT="1">test.csv</SrcDataSource>
        <FID>id</FID>
        <Field name="id" src="Id" type="Integer"  />
        <Field name="Test" src="Attrib" type="string" width="100" />
     </OGRVRTLayer>
    </OGRVRTDataSource>

And my command line:-

   ogr2ogr -append -f MSSQLSpatial "MSSQL:server=SQL01;database=TESTDB;trusted_connection=yes" test.vrt

The first error I get is:-

ERROR 1: Column ogr_geometry requested for geometry, but it does not exist.

After that there are errors trying to create the attribute field because the table does not exist. If I manually create the table in SQL Server with a single field named "id", then this command works (still with error messages).

Best Answer

The solution was to upgrade the GDAL core libraries. Lesson learned!