-
Notifications
You must be signed in to change notification settings - Fork 314
Closed
Labels
Hotfix Candidate 🚑Issues/PRs that are candidate for backporting to earlier supported versions.Issues/PRs that are candidate for backporting to earlier supported versions.
Description
Describe the bug
Reading output parameters of JSON type throws an error.
Exception message:
Stack trace:
Unhandled exception. System.OverflowException: Arithmetic operation resulted in an overflow.
at Microsoft.Data.SqlClient.TdsParserStateObject.TryReadPlpBytes(Byte[]& buff, Int32 offset, Int32 len, Int32& totalBytesRead) in C:\Users\apdeshmukh\git\fork\SqlClient\src\Microsoft.Data.SqlClient\src\Microsoft\Data\SqlClient\TdsParserStateObject.cs:line 1871
at Microsoft.Data.SqlClient.TdsParserStateObject.TryReadStringWithEncoding(Int32 length, Encoding encoding, Boolean isPlp, String& value) in C:\Users\apdeshmukh\git\fork\SqlClient\src\Microsoft.Data.SqlClient\src\Microsoft\Data\SqlClient\TdsParserStateObject.cs:line 1685
at Microsoft.Data.SqlClient.TdsParser.TryReadSqlStringValue(SqlBuffer value, Byte type, Int32 length, Encoding encoding, Boolean isPlp, TdsParserStateObject stateObj) in C:\Users\apdeshmukh\git\fork\SqlClient\src\Microsoft.Data.SqlClient\netcore\src\Microsoft\Data\SqlClient\TdsParser.cs:line 5985
at Microsoft.Data.SqlClient.TdsParser.TryReadSqlValue(SqlBuffer value, SqlMetaDataPriv md, Int32 length, TdsParserStateObject stateObj, SqlCommandColumnEncryptionSetting columnEncryptionOverride, String columnName, SqlCommand command) in C:\Users\apdeshmukh\git\fork\SqlClient\src\Microsoft.Data.SqlClient\netcore\src\Microsoft\Data\SqlClient\TdsParser.cs:line 6461
at Microsoft.Data.SqlClient.TdsParser.TryProcessReturnValue(Int32 length, TdsParserStateObject stateObj, SqlReturnValue& returnValue, SqlCommandColumnEncryptionSetting columnEncryptionSetting) in C:\Users\apdeshmukh\git\fork\SqlClient\src\Microsoft.Data.SqlClient\netcore\src\Microsoft\Data\SqlClient\TdsParser.cs:line 4413
at Microsoft.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) in C:\Users\apdeshmukh\git\fork\SqlClient\src\Microsoft.Data.SqlClient\netcore\src\Microsoft\Data\SqlClient\TdsParser.cs:line 2515
at Microsoft.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted) in C:\Users\apdeshmukh\git\fork\SqlClient\src\Microsoft.Data.SqlClient\netcore\src\Microsoft\Data\SqlClient\SqlCommand.cs:line 5298
at Microsoft.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean isAsync, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest) in C:\Users\apdeshmukh\git\fork\SqlClient\src\Microsoft.Data.SqlClient\netcore\src\Microsoft\Data\SqlClient\SqlCommand.cs:line 5168
at Microsoft.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry, String method) in C:\Users\apdeshmukh\git\fork\SqlClient\src\Microsoft.Data.SqlClient\netcore\src\Microsoft\Data\SqlClient\SqlCommand.cs:line 4845
at Microsoft.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, Boolean sendToPipe, Int32 timeout, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry, String methodName) in C:\Users\apdeshmukh\git\fork\SqlClient\src\Microsoft.Data.SqlClient\netcore\src\Microsoft\Data\SqlClient\SqlCommand.cs:line 1701
at Microsoft.Data.SqlClient.SqlCommand.ExecuteNonQuery() in C:\Users\apdeshmukh\git\fork\SqlClient\src\Microsoft.Data.SqlClient\netcore\src\Microsoft\Data\SqlClient\SqlCommand.cs:line 1221
Process terminated. Assertion failed.shmukh\source\repos\TestJsonOutputParam\Program.cs:line 64
dumping buffer
_inBytesRead = 268
_inBytesUsed = 74
used buffer:
04 01 01 0C 00 43 01 00 FF 11 00 C1 00 01 00 00
00 00 00 00 00 79 00 00 00 00 AC 00 00 09 40 00
6A 00 73 00 6F 00 6E 00 44 00 61 00 74 00 61 00
01 00 00 00 00 00 00 F4 FE FF FF FF FF FF FF FF
B7 00 00 00 7B 22 6D 65 6E 75
unused buffer:
22 3A 7B 22 69 64 22 3A 22 66 69 6C 65 22 2C 22
76 61 6C 75 65 22 3A 22 46 69 6C 65 22 2C 22 70
6F 70 75 70 22 3A 7B 22 6D 65 6E 75 69 74 65 6D
22 3A 5B 7B 22 76 61 6C 75 65 22 3A 22 4E 65 77
22 2C 22 6F 6E 63 6C 69 63 6B 22 3A 22 43 72 65
61 74 65 4E 65 77 44 6F 63 28 29 22 7D 2C 7B 22
76 61 6C 75 65 22 3A 22 4F 70 65 6E 22 2C 22 6F
6E 63 6C 69 63 6B 22 3A 22 4F 70 65 6E 44 6F 63
28 29 22 7D 2C 7B 22 76 61 6C 75 65 22 3A 22 43
6C 6F 73 65 22 2C 22 6F 6E 63 6C 69 63 6B 22 3A
22 43 6C 6F 73 65 44 6F 63 28 29 22 7D 5D 7D 7D
7D 00 00 00 00 FE 00 00 E0 00 00 00 00 00 00 00
00 00
at Microsoft.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) in C:\Users\apdeshmukh\git\fork\SqlClient\src\Microsoft.Data.SqlClient\netcore\src\Microsoft\Data\SqlClient\TdsParser.cs:line 2052
at Microsoft.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) in C:\Users\apdeshmukh\git\fork\SqlClient\src\Microsoft.Data.SqlClient\netcore\src\Microsoft\Data\SqlClient\TdsParser.cs:line 1937
at Microsoft.Data.SqlClient.TdsParser.DrainData(TdsParserStateObject stateObj) in C:\Users\apdeshmukh\git\fork\SqlClient\src\Microsoft.Data.SqlClient\netcore\src\Microsoft\Data\SqlClient\TdsParser.cs:line 4726
at Microsoft.Data.SqlClient.TdsParser.Deactivate(Boolean connectionIsDoomed) in C:\Users\apdeshmukh\git\fork\SqlClient\src\Microsoft.Data.SqlClient\netcore\src\Microsoft\Data\SqlClient\TdsParser.cs:line 1185
at Microsoft.Data.SqlClient.SqlInternalConnectionTds.InternalDeactivate() in C:\Users\apdeshmukh\git\fork\SqlClient\src\Microsoft.Data.SqlClient\netcore\src\Microsoft\Data\SqlClient\SqlInternalConnectionTds.cs:line 926
at Microsoft.Data.SqlClient.SqlInternalConnection.Deactivate() in C:\Users\apdeshmukh\git\fork\SqlClient\src\Microsoft.Data.SqlClient\src\Microsoft\Data\SqlClient\SqlInternalConnection.cs:line 369
at Microsoft.Data.ProviderBase.DbConnectionInternal.DeactivateConnection() in C:\Users\apdeshmukh\git\fork\SqlClient\src\Microsoft.Data.SqlClient\src\Microsoft\Data\ProviderBase\DbConnectionInternal.cs:line 565
at Microsoft.Data.ProviderBase.DbConnectionPool.DeactivateObject(DbConnectionInternal obj) in C:\Users\apdeshmukh\git\fork\SqlClient\src\Microsoft.Data.SqlClient\src\Microsoft\Data\ProviderBase\DbConnectionPool.cs:line 914
at Microsoft.Data.ProviderBase.DbConnectionPool.PutObject(DbConnectionInternal obj, Object owningObject) in C:\Users\apdeshmukh\git\fork\SqlClient\src\Microsoft.Data.SqlClient\src\Microsoft\Data\ProviderBase\DbConnectionPool.cs:line 1800
at Microsoft.Data.ProviderBase.DbConnectionInternal.CloseConnection(DbConnection owningObject, DbConnectionFactory connectionFactory) in C:\Users\apdeshmukh\git\fork\SqlClient\src\Microsoft.Data.SqlClient\src\Microsoft\Data\ProviderBase\DbConnectionInternal.cs:line 475
at Microsoft.Data.SqlClient.SqlConnection.CloseInnerConnection() in C:\Users\apdeshmukh\git\fork\SqlClient\src\Microsoft.Data.SqlClient\netcore\src\Microsoft\Data\SqlClient\SqlConnection.cs:line 1274
at Microsoft.Data.SqlClient.SqlConnection.Close() in C:\Users\apdeshmukh\git\fork\SqlClient\src\Microsoft.Data.SqlClient\netcore\src\Microsoft\Data\SqlClient\SqlConnection.cs:line 1325
at Microsoft.Data.SqlClient.SqlConnection.Dispose(Boolean disposing) in C:\Users\apdeshmukh\git\fork\SqlClient\src\Microsoft.Data.SqlClient\netcore\src\Microsoft\Data\SqlClient\SqlConnectionHelper.cs:line 173
at System.ComponentModel.Component.Dispose()
at Program.Main() in C:\Users\apdeshmukh\source\repos\TestJsonOutputParam\Program.cs:line 64
To reproduce
Include a complete code listing (or project/solution) that we can run to reproduce the issue.
Partial code listings, or multiple fragments of code, will slow down our response or cause us to push the issue back to you to provide code to reproduce the issue.
using Microsoft.Data;
using Microsoft.Data.SqlClient;
using System;
using System.Data;
class Program
{
private static string connectionString = Environment.GetEnvironmentVariable("CONNECTION_STR") ?? "Server=tcp:localhost,2799;Database=Demo2;Integrated Security=True;";
static void Main()
{
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
using (SqlCommand command = new SqlCommand("GetJsonData", connection))
//using (SqlCommand command = new SqlCommand("GetVarcharData", connection))
{
command.CommandType = CommandType.StoredProcedure;
// Output parameter
SqlParameter outputParam = new SqlParameter("@jsonData", SqlDbTypeExtensions.Json, -1)
//SqlParameter outputParam = new SqlParameter("@varcharData", SqlDbType.NVarChar, -1)
{
Direction = ParameterDirection.Output
};
command.Parameters.Add(outputParam);
// Execute the command
command.ExecuteNonQuery();
// Retrieve the value of the output parameter
string jsonData = (string)outputParam.Value;
Console.WriteLine("JSON Data: " + jsonData);
}
}
}
}
Expected behavior
Data should be populated in the output parameter.
Further technical details
Microsoft.Data.SqlClient version: 6.0.0
Additional context
NA
Metadata
Metadata
Assignees
Labels
Hotfix Candidate 🚑Issues/PRs that are candidate for backporting to earlier supported versions.Issues/PRs that are candidate for backporting to earlier supported versions.