I have a MapInfo Tab file that needs to be loaded to a MSSQL Server DDBB in a scheduled basis and I want to use OGR for this task. The tab is going to be appended in an existing DDBB table that has exactly the same structure (fields and data types).
I'm using the following command:
@ogr2ogr --config GDAL_DATA “C:\OSGeo\data\gdal\pcs.csv” -update -append -f MSSQLSpatial "MSSQL:server=servername;database=GIS;trusted_connection=yes" "\\gis\Maps\myTable.TAB" -nln dbo.myTable -lco "GEOM_NAME=SP_GEOMETRY" -lco "SPATIAL_INDEX=FALSE" -lco LAUNDER=NO -progress
I have tested this code successfully with other Tab files. However when I try to upload myTable.tab, the following error arises:
"INSERT command for new feature failed. [Microsoft][ODBC SQL Server Driver][SQL Server]The conversion of a varchar data type to a datetime data type resulted in an out-of-range value."
Meaning that OGR is dealing with the original "Datetime" fields as if they were varchar, and they don't fit the destination structure (correct me if I misinterpreted this..).
Don't know what I am doing wrong. Is there a way to explicitly tell OGR what datatypes to use for a specific field? I have seen -mapFieldType parameter, but this will modify all fields of the same type, and I don't want this. Is it possible to achieve this using the -sql parameter, and if so can you provide hints or sample code on how to begin with?