Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Insert to SQL Server throws exception - Specified type is not registered on the target server. #77

Open
valdisiljuconoks opened this issue Sep 28, 2022 · 1 comment

Comments

@valdisiljuconoks
Copy link

Hi,

I'm not sure about purpose of the library now. Is it meant to be able to work with spatial types or I can use it also to fill in tables in SQL server (2019)?

Using data tables I got follownig error:

[11:16:29 ERR] Error storing timetable dataset
System.InvalidOperationException: The given value of type SqlGeography from the data source cannot be converted to type udt of the specified target column.
 ---> System.ArgumentException: Specified type is not registered on the target server. Microsoft.SqlServer.Types.SqlGeography, Microsoft.SqlServer.Types, Version=2.5.0.0, Culture=neutral, PublicKeyToken=null.
   at System.Data.SqlClient.SqlConnection.GetInfoFromType(Type t)
   at System.Data.SqlClient.SqlConnection.GetBytes(Object o, Format& format, Int32& maxSize)
   at System.Data.SqlClient.SqlBulkCopy.ConvertValue(Object value, _SqlMetaData metadata, Boolean isNull, Boolean& isSqlType, Boolean& coercedToDataFeed)
   --- End of inner exception stack trace ---
   at System.Data.SqlClient.SqlBulkCopy.ConvertValue(Object value, _SqlMetaData metadata, Boolean isNull, Boolean& isSqlType, Boolean& coercedToDataFeed)
   at System.Data.SqlClient.SqlBulkCopy.ReadWriteColumnValueAsync(Int32 col)
   at System.Data.SqlClient.SqlBulkCopy.CopyColumnsAsync(Int32 col, TaskCompletionSource`1 source)
   at System.Data.SqlClient.SqlBulkCopy.CopyRowsAsync(Int32 rowsSoFar, Int32 totalRows, CancellationToken cts, TaskCompletionSource`1 source)
   at System.Data.SqlClient.SqlBulkCopy.CopyBatchesAsyncContinued(BulkCopySimpleResultSet internalResults, String updateBulkCommandText, CancellationToken cts, TaskCompletionSource`1 source)
   at System.Data.SqlClient.SqlBulkCopy.CopyBatchesAsync(BulkCopySimpleResultSet internalResults, String updateBulkCommandText, CancellationToken cts, TaskCompletionSource`1 source)
   at System.Data.SqlClient.SqlBulkCopy.WriteToServerInternalRestContinuedAsync(BulkCopySimpleResultSet internalResults, CancellationToken cts, TaskCompletionSource`1 source)
   at System.Data.SqlClient.SqlBulkCopy.WriteToServerInternalRestAsync(CancellationToken cts, TaskCompletionSource`1 source)
   at System.Data.SqlClient.SqlBulkCopy.WriteToServerInternalAsync(CancellationToken ctoken)
   at System.Data.SqlClient.SqlBulkCopy.WriteRowSourceToServerAsync(Int32 columnCount, CancellationToken ctoken)
   at System.Data.SqlClient.SqlBulkCopy.WriteToServer(DataTable table, DataRowState rowState)

Data table code:

table.Columns.Add(nameof(FlexibleAreaEntity.PosList), typeof(SqlGeography));

..

newRow[nameof(FlexibleAreaEntity.PosList)] =
    SqlGeography.STGeomFromText(new SqlChars($@"MULTIPOLYGON ((({_separator.Separate(item.PosList)})))"), 4326);

@thaianhduc
Copy link

@valdisiljuconoks I had the same problem. I changed to use Microsoft.Data.SqlClient instead of System.Data.SqlClient. It works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants