2

I am trying to import a Shapefile which is in EPSG:4326 coordinates to MSSQL Database but its failing. I am following the below command:

ogr2ogr -f MSSQLSpatial -overwrite "MSSQL:server=MSSQLServer_Name;database=dbname;trusted_connection=yes" -nln "output" "input.shp"

I get following error

ERROR 1: SQL Error SQLState=22018, NativeError=0, Msg=[Microsoft][SQL Server Native Client 11.0]Invalid character value for cast specification

ERROR 1: Unable to write feature 4195 from layer client_v01.
ERROR 1: Terminating translation prematurely after failed
translation of layer client_v01 (use -skipfailures to skip errors)
ERROR 1: SQL Error SQLState=HY000, NativeError=0, Msg=[Microsoft][SQL Server Native Client 11.0]Text column data incomplete

Then I tried to use -skipfailures but even that gave me error

ogr2ogr -f MSSQLSpatial -overwrite "MSSQL:server=MSSQLServer_Name;database=dbname;trusted_connection=yes" -nln "output" "input.shp" -skipfailures

Error as under

ERROR 1: SQL Error SQLState=22018, NativeError=0, Msg=[Microsoft][SQL Server Nat
ive Client 11.0]Invalid character value for cast specification

ERROR 1: SQL Error SQLState=42000, NativeError=4804, Msg=[Microsoft][SQL Server
Native Client 11.0][SQL Server]While reading current row from host, a premature
end-of-message was encountered--an incoming data stream was interrupted when the
 server expected to see more data. The host program may have terminated.

ERROR 1: SQL Error SQLState=22018, NativeError=0, Msg=[Microsoft][SQL Server Native Client 11.0]Invalid character value for cast specification

ERROR 1: SQL Error SQLState=42000, NativeError=4804, Msg=[Microsoft][SQL Server
Native Client 11.0][SQL Server]While reading current row from host, a premature
end-of-message was encountered--an incoming data stream was interrupted when the
 server expected to see more data. The host program may have terminated.

I read some of the posts and found it could be problem with coordinate system, therefore I used the below command.

ogr2ogr -f MSSQLSpatial -overwrite "MSSQL:server=MSSQLServer_Name;database=dbname;trusted_connection=yes" -nln "output" "input.shp" -s_srs EPSG:4326 -t_srs EPSG:4326

But got the same error.

Also, I saw some posts that mentions I should be having different geometry in the shapefile but I checked and I only have LineString.

Can someone help me get the Shapefile into the MSSQL database?

3

Your Answer

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

Browse other questions tagged or ask your own question.