Skip to content

Debug Assertion Failure : incorrect initial ParseSynonyms size #3016

@apoorvdeshmukh

Description

@apoorvdeshmukh

Describe the bug

A debug assertion is currently being failed in debug mode irrespective of connectionstring used in application code.

Exception message:
Stack trace:
Process terminated. Assertion failed.
incorrect initial ParseSynonyms size
   at Microsoft.Data.SqlClient.SqlConnectionString.GetParseSynonyms() in C:\Users\apdeshmukh\git\sqlclient\src\Microsoft.Data.SqlClient\src\Microsoft\Data\SqlClient\SqlConnectionString.cs:line 861
   at Microsoft.Data.SqlClient.SqlConnectionString..ctor(String connectionString) in C:\Users\apdeshmukh\git\sqlclient\src\Microsoft.Data.SqlClient\src\Microsoft\Data\SqlClient\SqlConnectionString.cs:line 291
   at Microsoft.Data.SqlClient.SqlConnectionFactory.CreateConnectionOptions(String connectionString, DbConnectionOptions previous) in C:\Users\apdeshmukh\git\sqlclient\src\Microsoft.Data.SqlClient\netcore\src\Microsoft\Data\SqlClient\SqlConnectionFactory.cs:line 144
   at Microsoft.Data.ProviderBase.DbConnectionFactory.GetConnectionPoolGroup(DbConnectionPoolKey key, DbConnectionPoolGroupOptions poolOptions, DbConnectionOptions& userConnectionOptions) in C:\Users\apdeshmukh\git\sqlclient\src\Microsoft.Data.SqlClient\src\Microsoft\Data\ProviderBase\DbConnectionFactory.cs:line 458
   at Microsoft.Data.SqlClient.SqlConnection.ConnectionString_Set(DbConnectionPoolKey key) in C:\Users\apdeshmukh\git\sqlclient\src\Microsoft.Data.SqlClient\netcore\src\Microsoft\Data\SqlClient\SqlConnectionHelper.cs:line 72
   at Microsoft.Data.SqlClient.SqlConnection.set_ConnectionString(String value) in C:\Users\apdeshmukh\git\sqlclient\src\Microsoft.Data.SqlClient\netcore\src\Microsoft\Data\SqlClient\SqlConnection.cs:line 651
   at Microsoft.Data.SqlClient.SqlConnection..ctor(String connectionString) in C:\Users\apdeshmukh\git\sqlclient\src\Microsoft.Data.SqlClient\netcore\src\Microsoft\Data\SqlClient\SqlConnection.cs:line 160
   at SqlExample.Program.Main(String[] args) in C:\Users\apdeshmukh\source\repos\TestSqlClient\Program.cs:line 14

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 System;
using Microsoft.Data.SqlClient;

namespace SqlExample
{
    class Program
    {
        static void Main(string[] args)
        {
            // Define your connection string
            string connString = @"Server=tcp:localhost;Database=Demo2";

            // Create a SQL connection
            using (SqlConnection conn = new SqlConnection(connString))
            {
                // Define your SQL query
                string query = "SELECT @@version";

                // Create a SQL command
                using (SqlCommand cmd = new SqlCommand(query, conn))
                {
                    try
                    {
                        // Open the connection
                        conn.Open();

                        // Execute the command and use a data reader to process the results
                        using (SqlDataReader reader = cmd.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                // Access data by column index or name
                                Console.WriteLine(reader.GetString(0));
                            }
                        }
                    }
                    catch (SqlException ex)
                    {
                        Console.WriteLine($"SQL Error: {ex.Message}");
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine($"Error: {ex.Message}");
                    }
                }
            }
        }
    }
}

Expected behavior

Version string printed correctly.
E.g. Microsoft SQL Server 2022 (RTM) - 16.0.5730.0 (X64)
Sep 10 2024 10:56:05 2022.0160.5730.00
Copyright (C) 2022 Microsoft Corporation
Enterprise Edition (64-bit) on Windows Server 2022 Datacenter 10.0 (Build 20348: ) (Hypervisor)

Further technical details

Microsoft.Data.SqlClient version: current main branch
.NET target: (e.g. Framework 4.7.1, Core 2.2.2) .Net 8.0
SQL Server version: (e.g. SQL Server 2017) Sql Server 2022
Operating system: (e.g. Windows 2019, Ubuntu 18.04, macOS 10.13, Docker container) : Windows

Additional context
This count needs to be corrected

Debug.Assert(synonyms.Count == count, "incorrect initial ParseSynonyms size");

Metadata

Metadata

Labels

Triage Done ✔️Issues that are triaged by dev team and are in investigation.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions