From a213d8e0c37cbb38a4622c8f72185d8b3b1902e9 Mon Sep 17 00:00:00 2001
From: Paul Medynski <31868385+paulmedynski@users.noreply.github.com>
Date: Wed, 3 Sep 2025 07:58:26 -0300
Subject: [PATCH 01/12] User Story 38467: Backport mac server name fix
- Backported part of #3494 and all of #3591:
  - Added configurable test jobs timeout, defaulting to 90 minutes.
  - Reduced generated database names to 96 chars to try to fix macOS test failures.Increase test jobs timeout (#3591)
- Fixed the unique name generators to:
  - Keep max lengths to 30 and 96 characters respectively.
  - Ensure uniqueness at the start of the names.
  - Added link to database identifier syntax.
---
 .../templates/jobs/ci-run-tests-job.yml       |   9 +
 .../jobs/run-tests-package-reference-job.yml  |  10 +
 .../templates/stages/ci-run-tests-stage.yml   |   7 +
 eng/pipelines/dotnet-sqlclient-ci-core.yml    |   6 +
 ...qlclient-ci-package-reference-pipeline.yml |   7 +
 ...qlclient-ci-project-reference-pipeline.yml |   7 +
 .../dotnet-sqlclient-signing-pipeline.yml     |   7 +
 .../ManualTests/AlwaysEncrypted/ApiShould.cs  |  10 +-
 .../AlwaysEncrypted/CspProviderExt.cs         |  49 -----
 .../ManualTests/DataCommon/DataTestUtility.cs | 198 ++++++++++++++----
 .../ProviderAgnostic/ReaderTest/ReaderTest.cs |   6 +-
 .../SQL/AdapterTest/AdapterTest.cs            |  10 +-
 .../SQL/ConnectivityTests/ConnectivityTest.cs |   2 +-
 .../DataClassificationTest.cs                 |   6 +-
 .../SQL/DataReaderTest/DataReaderTest.cs      |   2 +-
 .../SQL/DataStreamTest/DataStreamTest.cs      |  10 +-
 .../SQL/JsonTest/JsonBulkCopyTest.cs          |  10 +-
 .../SQL/JsonTest/JsonStreamTest.cs            |   4 +-
 .../SQL/ParameterTest/DateTimeVariantTest.cs  |  52 ++---
 .../SQL/ParameterTest/ParametersTest.cs       |  97 +++++++--
 .../ParameterTest/SqlAdapterUpdateBatch.cs    |   2 +-
 .../SQL/ParameterTest/SqlVariantParam.cs      |   4 +-
 .../RetryLogic/SqlCommandReliabilityTest.cs   |   4 +-
 .../SqlConnectionReliabilityTest.cs           |   2 +-
 .../AdjustPrecScaleForBulkCopy.cs             |   2 +-
 .../AzureDistributedTransaction.cs            |   2 +-
 .../CopyWidenNullInexactNumerics.cs           |   4 +-
 .../DataConversionErrorMessageTest.cs         |   2 +-
 .../SQL/SqlBulkCopyTest/WriteToServerTest.cs  |   4 +-
 .../SQL/SqlCommand/SqlCommandCompletedTest.cs |   2 +-
 .../SQL/SqlCommand/SqlCommandSetTest.cs       |   4 +-
 .../SqlFileStreamTest/SqlFileStreamTest.cs    |   4 +-
 .../SQL/UdtTest/SqlServerTypesTest.cs         |   2 +-
 .../SQL/UdtTest/UdtBulkCopyTest.cs            |   6 +-
 .../SQL/UdtTest/UdtDateTimeOffsetTest.cs      |   4 +-
 .../tests/ManualTests/SQL/UdtTest/UdtTest2.cs |  16 +-
 .../SQL/Utf8SupportTest/Utf8SupportTest.cs    |   2 +-
 37 files changed, 388 insertions(+), 187 deletions(-)
diff --git a/eng/pipelines/common/templates/jobs/ci-run-tests-job.yml b/eng/pipelines/common/templates/jobs/ci-run-tests-job.yml
index 66a2614c3e..e113692ab9 100644
--- a/eng/pipelines/common/templates/jobs/ci-run-tests-job.yml
+++ b/eng/pipelines/common/templates/jobs/ci-run-tests-job.yml
@@ -73,9 +73,18 @@ parameters:
       - Project
       - Package
 
+  # The timeout, in minutes, for this job.
+  - name: timeout
+    type: string
+    default: 90
+
 jobs:
 - job: ${{ format('{0}', coalesce(parameters.jobDisplayName, parameters.image, 'unknown_image')) }}
 
+  # Some of our tests take longer than the default 60 minutes to run on some
+  # OSes and configurations.
+  timeoutInMinutes: ${{ parameters.timeout }}
+
   pool:
     name: '${{ parameters.poolName }}'
     ${{ if eq(parameters.hostedPool, true) }}:
diff --git a/eng/pipelines/common/templates/jobs/run-tests-package-reference-job.yml b/eng/pipelines/common/templates/jobs/run-tests-package-reference-job.yml
index e729aaea46..14aea42411 100644
--- a/eng/pipelines/common/templates/jobs/run-tests-package-reference-job.yml
+++ b/eng/pipelines/common/templates/jobs/run-tests-package-reference-job.yml
@@ -20,11 +20,21 @@ parameters:
   - name: isPreview
     type: boolean
 
+  # The timeout, in minutes, for this job.
+  - name: timeout
+    type: string
+    default: 90
+
 jobs:
 - job: run_tests_package_reference
   displayName: 'Run tests with package reference'
   ${{ if ne(parameters.dependsOn, 'empty')}}:
     dependsOn: '${{parameters.dependsOn }}'
+
+  # Some of our tests take longer than the default 60 minutes to run on some
+  # OSes and configurations.
+  timeoutInMinutes: ${{ parameters.timeout }}
+
   pool:
     type: windows  # read more about custom job pool types at https://aka.ms/obpipelines/yaml/jobs
     isCustom: true
diff --git a/eng/pipelines/common/templates/stages/ci-run-tests-stage.yml b/eng/pipelines/common/templates/stages/ci-run-tests-stage.yml
index 3c1671a486..e07685407f 100644
--- a/eng/pipelines/common/templates/stages/ci-run-tests-stage.yml
+++ b/eng/pipelines/common/templates/stages/ci-run-tests-stage.yml
@@ -30,6 +30,11 @@ parameters:
     type: jobList
     default: []
 
+  # The timeout, in minutes, for each test job.
+  - name: testsTimeout
+    type: string
+    default: 90
+
 stages:
 - ${{ each config in parameters.testConfigurations }}:
   - ${{ each image in config.value.images }}:
@@ -47,6 +52,7 @@ stages:
                 parameters:
                   debug: ${{ parameters.debug }}
                   buildType: ${{ parameters.buildType }}
+                  timeout: ${{ parameters.testsTimeout }}
                   poolName: ${{ config.value.pool }}
                   hostedPool: ${{ eq(config.value.hostedPool, true) }}
                   image: ${{ image.value }}
@@ -72,6 +78,7 @@ stages:
                   parameters:
                     debug: ${{ parameters.debug }}
                     buildType: ${{ parameters.buildType }}
+                    timeout: ${{ parameters.testsTimeout }}
                     poolName: ${{ config.value.pool }}
                     hostedPool: ${{ eq(config.value.hostedPool, true) }}
                     image: ${{ image.value }}
diff --git a/eng/pipelines/dotnet-sqlclient-ci-core.yml b/eng/pipelines/dotnet-sqlclient-ci-core.yml
index 41a2a25416..eccb175593 100644
--- a/eng/pipelines/dotnet-sqlclient-ci-core.yml
+++ b/eng/pipelines/dotnet-sqlclient-ci-core.yml
@@ -57,6 +57,11 @@ parameters:
   type: string
   default: $(ci_var_defaultPoolName)
 
+# The timeout, in minutes, for each test job.
+- name: testsTimeout
+  type: string
+  default: 90
+
 variables:
   - template: libraries/ci-build-variables.yml@self
 
@@ -78,6 +83,7 @@ stages:
     parameters:
       debug: ${{ parameters.debug }}
       buildType: ${{ parameters.buildType }}
+      testsTimeout: ${{ parameters.testsTimeout }}
       ${{ if eq(parameters.buildType, 'Package') }}:
         dependsOn: build_nugets
 
diff --git a/eng/pipelines/dotnet-sqlclient-ci-package-reference-pipeline.yml b/eng/pipelines/dotnet-sqlclient-ci-package-reference-pipeline.yml
index 4956b15c89..48c50b284e 100644
--- a/eng/pipelines/dotnet-sqlclient-ci-package-reference-pipeline.yml
+++ b/eng/pipelines/dotnet-sqlclient-ci-package-reference-pipeline.yml
@@ -81,6 +81,12 @@ parameters: # parameters are shown up in ADO UI in a build queue time
     - Project
     - Package
 
+# The timeout, in minutes, for each test job.
+- name: testsTimeout
+  displayName: 'Tests timeout (in minutes)'
+  type: string
+  default: 90
+
 extends:
   template: dotnet-sqlclient-ci-core.yml@self
   parameters:
@@ -92,3 +98,4 @@ extends:
     useManagedSNI: ${{ parameters.useManagedSNI }}
     codeCovTargetFrameworks: ${{ parameters.codeCovTargetFrameworks }}
     buildType: ${{ parameters.buildType }}
+    testsTimeout: ${{ parameters.testsTimeout }}
diff --git a/eng/pipelines/dotnet-sqlclient-ci-project-reference-pipeline.yml b/eng/pipelines/dotnet-sqlclient-ci-project-reference-pipeline.yml
index ecdaacfafb..aaecbe7f17 100644
--- a/eng/pipelines/dotnet-sqlclient-ci-project-reference-pipeline.yml
+++ b/eng/pipelines/dotnet-sqlclient-ci-project-reference-pipeline.yml
@@ -73,6 +73,12 @@ parameters: # parameters are shown up in ADO UI in a build queue time
     - Project
     - Package
 
+# The timeout, in minutes, for each test job.
+- name: testsTimeout
+  displayName: 'Tests timeout (in minutes)'
+  type: string
+  default: 90
+
 extends:
   template: dotnet-sqlclient-ci-core.yml@self
   parameters:
@@ -84,3 +90,4 @@ extends:
     useManagedSNI: ${{ parameters.useManagedSNI }}
     codeCovTargetFrameworks: ${{ parameters.codeCovTargetFrameworks }}
     buildType: ${{ parameters.buildType }}
+    testsTimeout: ${{ parameters.testsTimeout }}
diff --git a/eng/pipelines/dotnet-sqlclient-signing-pipeline.yml b/eng/pipelines/dotnet-sqlclient-signing-pipeline.yml
index c0cc0ad521..c9fded9ed8 100644
--- a/eng/pipelines/dotnet-sqlclient-signing-pipeline.yml
+++ b/eng/pipelines/dotnet-sqlclient-signing-pipeline.yml
@@ -67,6 +67,12 @@ parameters: # parameters are shown up in ADO UI in a build queue time
   type: boolean
   default: false
 
+# The timeout, in minutes, for each test job.
+- name: testsTimeout
+  displayName: 'Tests timeout (in minutes)'
+  type: string
+  default: 90
+
 variables:
   - template: /eng/pipelines/libraries/variables.yml@self
   - name: packageFolderName
@@ -175,6 +181,7 @@ extends:
         parameters:
           packageFolderName: $(packageFolderName)
           isPreview: ${{ parameters['isPreview'] }}
+          timeout: ${{ parameters.testsTimeout }}
           downloadPackageStep:
             download: current
             artifact: $(packageFolderName)
diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/AlwaysEncrypted/ApiShould.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/AlwaysEncrypted/ApiShould.cs
index fc65ecabf5..eafbe76b69 100644
--- a/src/Microsoft.Data.SqlClient/tests/ManualTests/AlwaysEncrypted/ApiShould.cs
+++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/AlwaysEncrypted/ApiShould.cs
@@ -148,8 +148,8 @@ public void SqlParameterProperties(string connection)
             const string firstColumnName = @"firstColumn";
             const string secondColumnName = @"secondColumn";
             const string thirdColumnName = @"thirdColumn";
-            string inputProcedureName = DataTestUtility.GetUniqueName("InputProc").ToString();
-            string outputProcedureName = DataTestUtility.GetUniqueName("OutputProc").ToString();
+            string inputProcedureName = DataTestUtility.GetShortName("InputProc").ToString();
+            string outputProcedureName = DataTestUtility.GetShortName("OutputProc").ToString();
             const int charColumnSize = 100;
             const int decimalColumnPrecision = 10;
             const int decimalColumnScale = 4;
@@ -694,7 +694,7 @@ public void TestExecuteReader(string connection)
         [ClassData(typeof(AEConnectionStringProvider))]
         public async Task TestExecuteReaderAsyncWithLargeQuery(string connectionString)
         {
-            string randomName = DataTestUtility.GetUniqueName(Guid.NewGuid().ToString().Replace("-", ""), false);
+            string randomName = DataTestUtility.GetShortName(Guid.NewGuid().ToString().Replace("-", ""), false);
             if (randomName.Length > 50)
             {
                 randomName = randomName.Substring(0, 50);
@@ -878,8 +878,8 @@ public void TestEnclaveStoredProceduresWithAndWithoutParameters(string connectio
             using SqlCommand sqlCommand = new("", sqlConnection, transaction: null,
                 columnEncryptionSetting: SqlCommandColumnEncryptionSetting.Enabled);
 
-            string procWithoutParams = DataTestUtility.GetUniqueName("EnclaveWithoutParams", withBracket: false);
-            string procWithParam = DataTestUtility.GetUniqueName("EnclaveWithParams", withBracket: false);
+            string procWithoutParams = DataTestUtility.GetShortName("EnclaveWithoutParams", withBracket: false);
+            string procWithParam = DataTestUtility.GetShortName("EnclaveWithParams", withBracket: false);
 
             try
             {
diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/AlwaysEncrypted/CspProviderExt.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/AlwaysEncrypted/CspProviderExt.cs
index f164dff220..615eaf71bb 100644
--- a/src/Microsoft.Data.SqlClient/tests/ManualTests/AlwaysEncrypted/CspProviderExt.cs
+++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/AlwaysEncrypted/CspProviderExt.cs
@@ -157,55 +157,6 @@ public void TestRoundTripWithCSPAndCertStoreProvider()
             }
         }
 
-        [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringSetupForAE))]
-        [ClassData(typeof(AEConnectionStringProvider))]
-        public void TestEncryptDecryptWithCSP(string connectionString)
-        {
-            string providerName = @"Microsoft Enhanced RSA and AES Cryptographic Provider";
-            string keyIdentifier = DataTestUtility.GetUniqueNameForSqlServer("CSP");
-
-            try
-            {
-                CertificateUtilityWin.RSAPersistKeyInCsp(providerName, keyIdentifier);
-                string cspPath = String.Concat(providerName, @"/", keyIdentifier);
-
-                SQLSetupStrategyCspExt sqlSetupStrategyCsp = new SQLSetupStrategyCspExt(cspPath);
-                string tableName = sqlSetupStrategyCsp.CspProviderTable.Name;
-
-                try
-                {
-                    using SqlConnection sqlConn = new(connectionString);
-                    sqlConn.Open();
-
-                    Table.DeleteData(tableName, sqlConn);
-
-                    // insert 1 row data
-                    Customer customer = new Customer(45, "Microsoft", "Corporation");
-
-                    DatabaseHelper.InsertCustomerData(sqlConn, null, tableName, customer);
-
-                    // Test INPUT parameter on an encrypted parameter
-                    using SqlCommand sqlCommand = new(@$"SELECT CustomerId, FirstName, LastName FROM [{tableName}] WHERE FirstName = @firstName",
-                                                                sqlConn, null, SqlCommandColumnEncryptionSetting.Enabled);
-                    SqlParameter customerFirstParam = sqlCommand.Parameters.AddWithValue(@"firstName", @"Microsoft");
-                    Console.WriteLine(@"Exception: {0}");
-                    customerFirstParam.Direction = System.Data.ParameterDirection.Input;
-
-                    using SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
-                    ValidateResultSet(sqlDataReader);
-                }
-                finally
-                {
-                    // clean up database resources
-                    sqlSetupStrategyCsp.Dispose();
-                }
-            }
-            finally
-            {
-                CertificateUtilityWin.RSADeleteKeyInCsp(providerName, keyIdentifier);
-            }
-        }
-
         /// 
         /// Validates that the results are the ones expected.
         /// 
diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/DataCommon/DataTestUtility.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/DataCommon/DataTestUtility.cs
index dfdf1f8443..82ef6c2b17 100644
--- a/src/Microsoft.Data.SqlClient/tests/ManualTests/DataCommon/DataTestUtility.cs
+++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/DataCommon/DataTestUtility.cs
@@ -116,7 +116,7 @@ public static bool TcpConnectionStringDoesNotUseAadAuth
         {
             get
             {
-                SqlConnectionStringBuilder builder = new (TCPConnectionString);
+                SqlConnectionStringBuilder builder = new(TCPConnectionString);
                 return builder.Authentication == SqlAuthenticationMethod.SqlPassword || builder.Authentication == SqlAuthenticationMethod.NotSpecified;
             }
         }
@@ -548,48 +548,176 @@ public static bool DoesHostAddressContainBothIPv4AndIPv6()
             }
         }
 
+        // Generate a new GUID and return the characters from its 1st and 4th
+        // parts, as shown here:
+        //
+        //   7ff01cb8-88c7-11f0-b433-00155d7e531e
+        //   ^^^^^^^^           ^^^^
+        //
+        // These 12 characters are concatenated together without any
+        // separators.  These 2 parts typically comprise a timestamp and clock
+        // sequence, most likely to be unique for tests that generate names in
+        // quick succession.
+        private static string GetGuidParts()
+        {
+            var guid = Guid.NewGuid().ToString();
+            // GOTCHA: The slice operator is inclusive of the start index and
+            // exclusive of the end index!
+            return guid.Substring(0, 8) + guid.Substring(19, 4);
+        }
+
         /// 
-        /// Generate a unique name to use in Sql Server; 
-        /// some providers does not support names (Oracle supports up to 30).
+        /// Generate a short unique database object name, whose maximum length
+        /// is 30 characters, with the format:
+        ///
+        ///   _
+        ///
+        /// The Prefix will be truncated to satisfy the overall maximum length.
+        ///
+        /// The GUID parts will be the characters from the 1st and 4th blocks
+        /// from a traditional string representation, as shown here:
+        ///
+        ///   7ff01cb8-88c7-11f0-b433-00155d7e531e
+        ///   ^^^^^^^^           ^^^^
+        ///
+        /// These 2 parts typically comprise a timestamp and clock sequence,
+        /// most likely to be unique for tests that generate names in quick
+        /// succession.  The 12 characters are concatenated together without any
+        /// separators.
         /// 
-        /// The name length will be no more then (16 + prefix.Length + escapeLeft.Length + escapeRight.Length).
-        /// Name without brackets.
-        /// Unique name by considering the Sql Server naming rules.
-        public static string GetUniqueName(string prefix, bool withBracket = true)
+        /// 
+        /// 
+        /// The prefix to use when generating the unique name, truncated to at
+        /// most 18 characters when withBracket is false, and 16 characters when
+        /// withBracket is true.
+        ///
+        /// This should not contain any characters that cannot be used in
+        /// database object names.  See:
+        /// 
+        /// https://learn.microsoft.com/en-us/sql/relational-databases/databases/database-identifiers?view=sql-server-ver17#rules-for-regular-identifiers
+        /// 
+        /// 
+        /// 
+        /// When true, the entire generated name will be enclosed in square
+        /// brackets, for example:
+        /// 
+        ///   [MyPrefix_7ff01cb811f0]
+        /// 
+        /// 
+        /// 
+        /// A unique database object name, no more than 30 characters long.
+        /// 
+        public static string GetShortName(string prefix, bool withBracket = true)
         {
-            string escapeLeft = withBracket ? "[" : string.Empty;
-            string escapeRight = withBracket ? "]" : string.Empty;
-            string uniqueName = string.Format("{0}{1}_{2}_{3}{4}",
-                escapeLeft,
-                prefix,
-                DateTime.Now.Ticks.ToString("X", CultureInfo.InvariantCulture), // up to 8 characters
-                Guid.NewGuid().ToString().Substring(0, 6), // take the first 6 characters only
-                escapeRight);
-            return uniqueName;
+            StringBuilder name = new(30);
+
+            if (withBracket)
+            {
+                name.Append('[');
+            }
+
+            int maxPrefixLength = withBracket ? 16 : 18;
+            if (prefix.Length > maxPrefixLength)
+            {
+                prefix = prefix.Substring(0, maxPrefixLength);
+            }
+
+            name.Append(prefix);
+            name.Append('_');
+            name.Append(GetGuidParts());
+
+            if (withBracket)
+            {
+                name.Append(']');
+            }
+
+            return name.ToString();
         }
 
         /// 
-        /// Uses environment values `UserName` and `MachineName` in addition to the specified `prefix` and current date
-        /// to generate a unique name to use in Sql Server; 
-        /// SQL Server supports long names (up to 128 characters), add extra info for troubleshooting.
+        /// Generate a long unique database object name, whose maximum length is
+        /// 96 characters, with the format:
+        /// 
+        ///   ___
+        ///
+        /// The Prefix will be truncated to satisfy the overall maximum length.
+        ///
+        /// The GUID Parts will be the characters from the 1st and 4th blocks
+        /// from a traditional string representation, as shown here:
+        ///
+        ///   7ff01cb8-88c7-11f0-b433-00155d7e531e
+        ///   ^^^^^^^^           ^^^^
+        ///
+        /// These 2 parts typically comprise a timestamp and clock sequence,
+        /// most likely to be unique for tests that generate names in quick
+        /// succession.  The 12 characters are concatenated together without any
+        /// separators.
+        ///
+        /// The UserName and MachineName are obtained from the Environment,
+        /// and will be truncated to satisfy the maximum overall length.
         /// 
-        /// Add the prefix to the generate string.
-        /// Database name must be pass with brackets by default.
-        /// Unique name by considering the Sql Server naming rules.
-        public static string GetUniqueNameForSqlServer(string prefix, bool withBracket = true)
+        /// 
+        /// 
+        /// The prefix to use when generating the unique name, truncated to at
+        /// most 32 characters.
+        ///
+        /// This should not contain any characters that cannot be used in
+        /// database object names.  See:
+        /// 
+        /// https://learn.microsoft.com/en-us/sql/relational-databases/databases/database-identifiers?view=sql-server-ver17#rules-for-regular-identifiers
+        /// 
+        /// 
+        /// 
+        /// When true, the entire generated name will be enclosed in square
+        /// brackets, for example:
+        /// 
+        ///   [MyPrefix_7ff01cb811f0_test_user_ci_agent_machine_name]
+        /// 
+        /// 
+        /// 
+        /// A unique database object name, no more than 96 characters long.
+        /// 
+        public static string GetLongName(string prefix, bool withBracket = true)
         {
-            string extendedPrefix = string.Format(
-                "{0}_{1}_{2}@{3}",
-                prefix,
-                Environment.UserName,
-                Environment.MachineName,
-                DateTime.Now.ToString("yyyy_MM_dd", CultureInfo.InvariantCulture));
-            string name = GetUniqueName(extendedPrefix, withBracket);
-            if (name.Length > 128)
-            {
-                throw new ArgumentOutOfRangeException("the name is too long - SQL Server names are limited to 128");
-            }
-            return name;
+            StringBuilder name = new(96);
+
+            if (withBracket)
+            {
+                name.Append('[');
+            }
+
+            if (prefix.Length > 32)
+            {
+                prefix = prefix.Substring(0, 32);
+            }
+
+            name.Append(prefix);
+            name.Append('_');
+            name.Append(GetGuidParts());
+            name.Append('_');
+
+            var suffix =
+              Environment.UserName + '_' +
+              Environment.MachineName;
+
+            int maxSuffixLength = 96 - name.Length;
+            if (withBracket)
+            {
+                --maxSuffixLength;
+            }
+            if (suffix.Length > maxSuffixLength)
+            {
+                suffix = suffix.Substring(0, maxSuffixLength);
+            }
+
+            name.Append(suffix);
+
+            if (withBracket)
+            {
+                name.Append(']');
+            }
+
+            return name.ToString();
         }
 
         public static void CreateTable(SqlConnection sqlConnection, string tableName, string createBody)
diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/ProviderAgnostic/ReaderTest/ReaderTest.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/ProviderAgnostic/ReaderTest/ReaderTest.cs
index c99fe94807..50e2b9253c 100644
--- a/src/Microsoft.Data.SqlClient/tests/ManualTests/ProviderAgnostic/ReaderTest/ReaderTest.cs
+++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/ProviderAgnostic/ReaderTest/ReaderTest.cs
@@ -19,7 +19,7 @@ public static void TestMain()
         {
             string connectionString = DataTestUtility.TCPConnectionString;
 
-            string tempTable = DataTestUtility.GetUniqueNameForSqlServer("table");
+            string tempTable = DataTestUtility.GetLongName("table");
 
             DbProviderFactory provider = SqlClientFactory.Instance;
             try
@@ -275,7 +275,7 @@ public static void TestMain()
         [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsNotAzureSynapse))]
         public static void SqlDataReader_SqlBuffer_GetFieldValue()
         {
-            string tableName = DataTestUtility.GetUniqueNameForSqlServer("SqlBuffer_GetFieldValue");
+            string tableName = DataTestUtility.GetLongName("SqlBuffer_GetFieldValue");
             DateTimeOffset dtoffset = DateTimeOffset.Now;
             DateTime dt = DateTime.Now;
             //Exclude the millisecond because of rounding at some points by SQL Server.
@@ -374,7 +374,7 @@ public static void SqlDataReader_SqlBuffer_GetFieldValue()
         [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsNotAzureSynapse))]
         public static async Task SqlDataReader_SqlBuffer_GetFieldValue_Async()
         {
-            string tableName = DataTestUtility.GetUniqueNameForSqlServer("SqlBuffer_GetFieldValue_Async");
+            string tableName = DataTestUtility.GetLongName("SqlBuffer_GetFieldValue_Async");
             DateTimeOffset dtoffset = DateTimeOffset.Now;
             DateTime dt = DateTime.Now;
             //Exclude the millisecond because of rounding at some points by SQL Server.
diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/AdapterTest/AdapterTest.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/AdapterTest/AdapterTest.cs
index 439406dadb..552fbf3119 100644
--- a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/AdapterTest/AdapterTest.cs
+++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/AdapterTest/AdapterTest.cs
@@ -54,7 +54,7 @@ public class AdapterTest
         public AdapterTest()
         {
             // create random name for temp tables
-            _tempTable = DataTestUtility.GetUniqueName("AdapterTest");
+            _tempTable = DataTestUtility.GetShortName("AdapterTest");
             _tempTable = _tempTable.Replace('-', '_');
 
             _randomGuid = Guid.NewGuid().ToString();
@@ -555,7 +555,7 @@ public void ParameterTest_AllTypes()
         [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsNotAzureSynapse))]
         public void ParameterTest_InOut()
         {
-            string procName = DataTestUtility.GetUniqueName("P");
+            string procName = DataTestUtility.GetShortName("P");
             // input, output
             string spCreateInOut =
                 "CREATE PROCEDURE " + procName + " @in int, @inout int OUTPUT, @out nvarchar(8) OUTPUT " +
@@ -836,13 +836,13 @@ public void BulkUpdateTest()
         [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsNotAzureSynapse))]
         public void UpdateRefreshTest()
         {
-            string identTableName = DataTestUtility.GetUniqueName("ID_");
+            string identTableName = DataTestUtility.GetShortName("ID_");
             string createIdentTable =
                 $"CREATE TABLE {identTableName} (id int IDENTITY," +
                 "LastName nvarchar(50) NULL," +
                 "Firstname nvarchar(50) NULL)";
 
-            string spName = DataTestUtility.GetUniqueName("sp_insert", withBracket: false);
+            string spName = DataTestUtility.GetShortName("sp_insert", withBracket: false);
             string spCreateInsert =
                 $"CREATE PROCEDURE {spName}" +
                 "(@FirstName nvarchar(50), @LastName nvarchar(50), @id int OUTPUT) " +
@@ -1155,7 +1155,7 @@ public void AutoGenUpdateTest()
         [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsNotAzureSynapse))]
         public void AutoGenErrorTest()
         {
-            string identTableName = DataTestUtility.GetUniqueName("ID_");
+            string identTableName = DataTestUtility.GetShortName("ID_");
             string createIdentTable =
                 $"CREATE TABLE {identTableName} (id int IDENTITY," +
                 "LastName nvarchar(50) NULL," +
diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ConnectivityTests/ConnectivityTest.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ConnectivityTests/ConnectivityTest.cs
index e9e29e5940..4f84381bd8 100644
--- a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ConnectivityTests/ConnectivityTest.cs
+++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ConnectivityTests/ConnectivityTest.cs
@@ -393,7 +393,7 @@ public static async Task ConnectionOpenAsyncDisableRetry()
         {
             SqlConnectionStringBuilder connectionStringBuilder = new(DataTestUtility.TCPConnectionString)
             {
-                InitialCatalog = DataTestUtility.GetUniqueNameForSqlServer("DoesNotExist", false),
+                InitialCatalog = DataTestUtility.GetLongName("DoesNotExist", false),
                 Pooling = false,
                 ConnectTimeout = 15,
                 ConnectRetryCount = 3
diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/DataClassificationTest/DataClassificationTest.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/DataClassificationTest/DataClassificationTest.cs
index 83eecc5b23..3e7076d52d 100644
--- a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/DataClassificationTest/DataClassificationTest.cs
+++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/DataClassificationTest/DataClassificationTest.cs
@@ -18,7 +18,7 @@ public static class DataClassificationTest
         [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsNotAzureSynapse), nameof(DataTestUtility.IsSupportedDataClassification))]
         public static void TestDataClassificationResultSetRank()
         {
-            s_tableName = DataTestUtility.GetUniqueNameForSqlServer("DC");
+            s_tableName = DataTestUtility.GetLongName("DC");
             using (SqlConnection sqlConnection = new SqlConnection(DataTestUtility.TCPConnectionString))
             using (SqlCommand sqlCommand = sqlConnection.CreateCommand())
             {
@@ -41,7 +41,7 @@ public static void TestDataClassificationResultSetRank()
         [ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsSupportedDataClassification))]
         public static void TestDataClassificationResultSet()
         {
-            s_tableName = DataTestUtility.GetUniqueNameForSqlServer("DC");
+            s_tableName = DataTestUtility.GetLongName("DC");
             using (SqlConnection sqlConnection = new SqlConnection(DataTestUtility.TCPConnectionString))
             using (SqlCommand sqlCommand = sqlConnection.CreateCommand())
             {
@@ -232,7 +232,7 @@ public static void TestDataClassificationBulkCopy()
             data.Rows.Add(Guid.NewGuid(), "Company 2", "sample2@contoso.com", 1);
             data.Rows.Add(Guid.NewGuid(), "Company 3", "sample3@contoso.com", 1);
 
-            var tableName = DataTestUtility.GetUniqueNameForSqlServer("DC");
+            var tableName = DataTestUtility.GetLongName("DC");
 
             using (var connection = new SqlConnection(DataTestUtility.TCPConnectionString))
             {
diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/DataReaderTest/DataReaderTest.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/DataReaderTest/DataReaderTest.cs
index d00ea1d226..60917e50e0 100644
--- a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/DataReaderTest/DataReaderTest.cs
+++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/DataReaderTest/DataReaderTest.cs
@@ -133,7 +133,7 @@ public static void CheckSparseColumnBit()
         [InlineData("Georgian_Modern_Sort_CI_AS")]
         public static void CollatedDataReaderTest(string collation)
         {
-            string dbName = DataTestUtility.GetUniqueName("CollationTest", false);
+            string dbName = DataTestUtility.GetShortName("CollationTest", false);
 
             SqlConnectionStringBuilder builder = new(DataTestUtility.TCPConnectionString)
             {
diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/DataStreamTest/DataStreamTest.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/DataStreamTest/DataStreamTest.cs
index 7fda024ed5..18de7b7133 100644
--- a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/DataStreamTest/DataStreamTest.cs
+++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/DataStreamTest/DataStreamTest.cs
@@ -50,7 +50,7 @@ public static async Task AsyncMultiPacketStreamRead()
 
             byte[] inputData = null;
             byte[] outputData = null;
-            string tableName = DataTestUtility.GetUniqueNameForSqlServer("data");
+            string tableName = DataTestUtility.GetLongName("data");
 
             using (SqlConnection connection = new(connectionString))
             {
@@ -546,7 +546,7 @@ private static void RowBuffer(string connectionString)
 
         private static void TimestampRead(string connectionString)
         {
-            string tempTable = DataTestUtility.GetUniqueNameForSqlServer("##Temp");
+            string tempTable = DataTestUtility.GetLongName("##Temp");
             tempTable = tempTable.Replace('-', '_');
 
             using (SqlConnection conn = new SqlConnection(connectionString))
@@ -1041,7 +1041,7 @@ private static void SequentialAccess(string connectionString)
 
         private static void NumericRead(string connectionString)
         {
-            string tempTable = DataTestUtility.GetUniqueNameForSqlServer("##Temp");
+            string tempTable = DataTestUtility.GetLongName("##Temp");
             tempTable = tempTable.Replace('-', '_');
 
             using (SqlConnection conn = new SqlConnection(connectionString))
@@ -1871,8 +1871,8 @@ private static void StreamingBlobDataTypes(string connectionString)
 
         private static void VariantCollationsTest(string connectionString)
         {
-            string dbName = DataTestUtility.GetUniqueName("JPN");
-            string tableName = DataTestUtility.GetUniqueName("T");
+            string dbName = DataTestUtility.GetShortName("JPN");
+            string tableName = DataTestUtility.GetShortName("T");
 
             using (SqlConnection connection = new SqlConnection(connectionString))
             {
diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/JsonTest/JsonBulkCopyTest.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/JsonTest/JsonBulkCopyTest.cs
index 816537cb8f..98f7e87071 100644
--- a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/JsonTest/JsonBulkCopyTest.cs
+++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/JsonTest/JsonBulkCopyTest.cs
@@ -26,11 +26,11 @@ public IEnumerator