snowflake-connector-net icon indicating copy to clipboard operation
snowflake-connector-net copied to clipboard

SNOW-970857: Parameter DbType should track explicit assignment rather than hard default to AnsiString

Open mgravell opened this issue 1 year ago • 5 comments

Currently DbType is a basic auto-implemented property: https://github.com/snowflakedb/snowflake-connector-net/blob/master/Snowflake.Data/Client/SnowflakeDbParameter.cs#L37

This causes problems because it defaults to AnsiString (value zero) (because)

To complicate things: multiple providers have types where setting the DbType is actively discouraged, because they will use additional types internally when assigned. This means that provider-agnostic tools (think "Dapper") actively choose not to set this property in those cases, which causes problems.

The way most providers do this is to track explicit assignment; if it has never actively been assigned a value, then the get value is inferred from the .Value (or other mechanisms).

Examples:

  • https://github.com/npgsql/npgsql/blob/main/src/Npgsql/NpgsqlParameter.cs#L314
  • https://github.com/dotnet/SqlClient/blob/d30d9d107eca0f11b735a550aa187e57167858c9/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlParameter.cs#L462

I suggest this provider should do something similar, to avoid the problem where if DbType is not set, things are sent as AnsiString

mgravell avatar Nov 15 '23 08:11 mgravell

hi and thank you for raising this issue and especially for the detailed description of how this would be useful ! we'll take a look at this enhancement request.

sfc-gh-dszmolka avatar Nov 17 '23 11:11 sfc-gh-dszmolka

@sfc-gh-dszmolka please prioritize this, we're forced to use no longer supported versions (1.x) due to this. I'd classify this as a bug, as a matter of fact.

amis92 avatar Nov 28 '23 10:11 amis92

Sure - let us sync internally and the driver team can decide what's the best to move forward with this issue. Thank you for bearing with us !

sfc-gh-dszmolka avatar Nov 28 '23 17:11 sfc-gh-dszmolka

PR in review https://github.com/snowflakedb/snowflake-connector-net/pull/889

sfc-gh-dszmolka avatar Mar 27 '24 07:03 sfc-gh-dszmolka

PR merged and fix will be part of the 2024 April release, towards the end of month

sfc-gh-dszmolka avatar Apr 02 '24 04:04 sfc-gh-dszmolka

Will update this thread once more information is known about the next upcoming major release of the .NET driver which will carry this fix.

edit: confirming with Product team; release should be available by mid-July 2024

sfc-gh-dszmolka avatar Jun 24 '24 09:06 sfc-gh-dszmolka

fix released with Snowflake .NET driver version v4.0.0 in July 2024

sfc-gh-dszmolka avatar Jul 09 '24 07:07 sfc-gh-dszmolka