Skip to content

Add geometry for sqlbulkcopy : string to geometry autoconverter #3526

@rferraton

Description

@rferraton

Is your feature request related to a problem? Please describe.

Currently i cannot load geometry data easily from other database into SQL Server using SqlBulkCopy.
It failed with error like :

The given value 'POINT (4.462979994 45.854021923)' of type String from the data source cannot be converted to the UDT type for column 48 [geo_point_2d]

StackTrace :    at Microsoft.Data.SqlClient.SqlConnection.GetInfoFromType(Type t)
   at Microsoft.Data.SqlClient.SqlConnection.GetBytes(Object o, Format& format, Int32& maxSize)
   at Microsoft.Data.SqlClient.SqlConnection.GetBytes(Object o)
   at Microsoft.Data.SqlClient.SqlBulkCopy.ConvertValue(Object value, _SqlMetaData metadata, Boolean isNull, Boolean& isSqlType, Boolean& coercedToDataFeed)

Describe the solution you'd like

Autoconvert (or try to convert) STRING to GEOMETRY when using SqlBulkCopy

Describe alternatives you've considered

Load data into a varchar(max) column and convert into GEOMETRY in T-SQL.

Additional context

I tried to convert geometry datatypes from DuckDB to MSSQL.

DuckDB have a spatial extension. and this extention have a ST_asTEXT() fonction that return a string like POINT(..,,..)
It also have a ST_asJSON() (tested without succès). Native DuckDB GEOMETRY datatype are seen as UnmanagedMemoryStream (that is also not managed by SqlBulkCopy Converter but this is normal)

Metadata

Metadata

Labels

Needs More Info ℹ️Issues that have insufficient information to pursue investigationsTriage Needed 🆕For new issues, not triaged yet.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions