Skip to content

Commit 7ec2095

Browse files
authored
Allow large UDT buffers for netfx (#456)
1 parent 0b8d7b5 commit 7ec2095

File tree

4 files changed

+27
-11
lines changed

4 files changed

+27
-11
lines changed

src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlUtil.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,12 @@ static internal Exception UDTInvalidSqlType(string typeName)
817817
{
818818
return ADP.Argument(StringsHelper.GetString(Strings.SQLUDT_InvalidSqlType, typeName));
819819
}
820+
821+
static internal Exception UDTInvalidSize(int maxSize, int maxSupportedSize)
822+
{
823+
throw ADP.ArgumentOutOfRange(StringsHelper.GetString(Strings.SQLUDT_InvalidSize, maxSize, maxSupportedSize));
824+
}
825+
820826

821827
static internal Exception InvalidSqlDbTypeForConstructor(SqlDbType type)
822828
{

src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/TdsParser.cs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9980,10 +9980,12 @@ internal Task TdsExecuteRPC(SqlCommand cmd, _SqlRPC[] rpcArray, int timeout, boo
99809980

99819981
Debug.Assert(_isYukon, "Invalid DataType UDT for non-Yukon or later server!");
99829982

9983+
int maxSupportedSize = IsKatmaiOrNewer ? int.MaxValue : short.MaxValue;
9984+
99839985
if (!isNull)
99849986
{
99859987
// When writing UDT parameter values to the TDS stream, allow sending byte[] or SqlBytes
9986-
// directly to the server and not rejected as invalid. This allows users to handle
9988+
// directly to the server and not reject them as invalid. This allows users to handle
99879989
// serialization and deserialization logic without having to have SqlClient be aware of
99889990
// the types and without using inefficient text representations.
99899991
if (value is byte[] rawBytes)
@@ -10014,19 +10016,15 @@ internal Task TdsExecuteRPC(SqlCommand cmd, _SqlRPC[] rpcArray, int timeout, boo
1001410016
size = udtVal.Length;
1001510017

1001610018
//it may be legitimate, but we dont support it yet
10017-
if (size < 0 || (size >= UInt16.MaxValue && maxsize != -1))
10018-
throw new IndexOutOfRangeException();
10019+
if (size < 0 || (size >= maxSupportedSize && maxsize != -1))
10020+
{
10021+
throw SQL.UDTInvalidSize(maxsize, maxSupportedSize);
10022+
}
1001910023
}
1002010024

10021-
//if this is NULL value, write special null value
10022-
byte[] lenBytes = BitConverter.GetBytes((Int64)size);
10023-
10024-
if (ADP.IsEmpty(param.UdtTypeName))
10025-
throw SQL.MustSetUdtTypeNameForUdtParams();
10026-
1002710025
// Split the input name. TypeName is returned as single 3 part name during DeriveParameters.
1002810026
// NOTE: ParseUdtTypeName throws if format is incorrect
10029-
String[] names = SqlParameter.ParseTypeName(param.UdtTypeName, true /* is UdtTypeName */);
10027+
String[] names = SqlParameter.ParseTypeName(param.UdtTypeName, isUdtTypeName: true);
1003010028
if (!ADP.IsEmpty(names[0]) && TdsEnums.MAX_SERVERNAME < names[0].Length)
1003110029
{
1003210030
throw ADP.ArgumentOutOfRange("names");

src/Microsoft.Data.SqlClient/netfx/src/Resources/Strings.Designer.cs

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Microsoft.Data.SqlClient/netfx/src/Resources/Strings.resx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4527,4 +4527,7 @@
45274527
<data name="TCE_AttestationProtocolNotSpecifiedForGeneratingEnclavePackage" xml:space="preserve">
45284528
<value>Error occurred when generating enclave package. Attestation Protocol has not been specified in the connection string, but the query requires enclave computations.</value>
45294529
</data>
4530-
</root>
4530+
<data name="SQLUDT_InvalidSize" xml:space="preserve">
4531+
<value>UDT size must be less than {1}, size: {0}</value>
4532+
</data>
4533+
</root>

0 commit comments

Comments
 (0)