I just found out that when you use DataTable and SqlBulkCopy in an attempt to load a SQL Server table, you can't use big decimal values.
DataTable only supports the .NET decimal type. .NET decimal is smaller than SQL Server decimal, so when you exceed the .NET range, you get an exception.
I prepared a DataTable that contains data rows with SqlDecimal columns and tried to bulk-load it.
bulkCopy.WriteToServer(dt);
But I get this error:
InvalidCastException: Failed to convert parameter value from a SqlDecimal to a Decimal.
Is there a workaround for this problem?
Update: After David's answer I double-checked the error. It turns out that it is not decimal but smallmoney column that caused this issue. An attempt to put SqlDecimal into smallmoney raises an error. It is very easy to avoid, for smallmoney and money columns .NET decimal is big enough.
I can't repro that.