From 796448de4411cc82c5b48d841c56a584339336f9 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Fri, 6 Mar 2026 23:31:34 +1100 Subject: [PATCH] Use using declaration for paramsCmd Change local SqlCommand instantiation to a using declaration so paramsCmd is disposed automatically. This ensures the command is disposed at the end of the scope and prevents potential resource leaks while preserving the CommandType = StoredProcedure initialization. --- .../src/Microsoft/Data/SqlClient/SqlCommand.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlCommand.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlCommand.cs index 2ff95f2e3b..65541d5e3a 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlCommand.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlCommand.cs @@ -1346,7 +1346,7 @@ internal void DeriveParameters() useManagedDataType = false; } - SqlCommand paramsCmd = new SqlCommand(cmdText.ToString(), Connection, Transaction) + using SqlCommand paramsCmd = new SqlCommand(cmdText.ToString(), Connection, Transaction) { CommandType = CommandType.StoredProcedure };