Skip to content

MDS 4.0+ Fails in .NET 4.8 when using AG (FailoverPartner) #1594

@cmeyertons

Description

@cmeyertons

Describe the bug

A clear and concise description of what the bug is.

If you are seeing an exception, include the full exceptions details (message and stack trace).

Exception message:
Stack trace:
System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary. at System.ThrowHelper.ThrowKeyNotFoundException() 
at System.Collections.Generic.Dictionary`2.get_Item(TKey key) 
at Microsoft.Data.SqlClient.SqlConnectionPoolGroupProviderInfo.CreateFailoverPermission(SqlConnectionString userConnectionOptions, String actualFailoverPartner) 
in D:\a\_work\1\s\src\Microsoft.Data.SqlClient\src\Microsoft\Data\SqlClient\SqlConnectionPoolGroupProviderInfo.cs:line 107 
at Microsoft.Data.SqlClient.SqlConnectionPoolGroupProviderInfo.FailoverCheck(Boolean actualUseFailoverPartner, SqlConnectionString userConnectionOptions, String actualFailoverPartner) 
in D:\a\_work\1\s\src\Microsoft.Data.SqlClient\src\Microsoft\Data\SqlClient\SqlConnectionPoolGroupProviderInfo.cs:line 66 
at Microsoft.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString connectionOptions, SqlCredential credential, TimeoutTimer timeout)
....

It looks like we are checking for existence of the FailoverPartner keyword by trying to access a dictionary and seeing if it returns null here?

To reproduce

var csb = new Microsoft.Data.SqlClient.SqlConnectionStringBuilder()
{
	DataSource = db.ServerName, // the raw server name, not AG listener
	InitialCatalog = db.DBname,
	TrustServerCertificate = true,
	IntegratedSecurity = true,
};

using (var c = new Microsoft.Data.SqlClient.SqlConnection(csb.ToString()))
{
	c.Execute("SELECT TOP 1 1 FROM dbo.Entity");
}

Expected behavior

Should be able to connect when database is in an AG.

Further technical details

Microsoft.Data.SqlClient version: 4.0
.NET target: net48
SQL Server version: SQL Server 2019
Operating system: Windows 2019

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions