Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System.Collections.Generic.KeyNotFoundException #1613

Closed
pengweiqhca opened this issue May 13, 2022 · 10 comments
Closed

System.Collections.Generic.KeyNotFoundException #1613

pengweiqhca opened this issue May 13, 2022 · 10 comments

Comments

@pengweiqhca
Copy link

pengweiqhca commented May 13, 2022

https://github.com/dotnet/SqlClient/blob/main/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlConnectionPoolGroupProviderInfo.cs#L107

System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary。
    at TValue System.Collections.Generic.Dictionary<TKey, TValue>.get_Item(TKey key)
    at PermissionSet Microsoft.Data.SqlClient.SqlConnectionPoolGroupProviderInfo.CreateFailoverPermission(SqlConnectionString userConnectionOptions, string actualFailoverPartner)
    at void Microsoft.Data.SqlClient.SqlConnectionPoolGroupProviderInfo.FailoverCheck(bool actualUseFailoverPartner, SqlConnectionString userConnectionOptions, string actualFailoverPartner)
    at void Microsoft.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, string newPassword, SecureString newSecurePassword, bool redirectedUserInstance, SqlConnectionString connectionOptions, SqlCredential credential, TimeoutTimer timeout)
    at void Microsoft.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout, SqlConnectionString connectionOptions, SqlCredential credential, string newPassword, SecureString newSecurePassword, bool redirectedUserInstance)
    at new Microsoft.Data.SqlClient.SqlInternalConnectionTds(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, object providerInfo, string newPassword, SecureString newSecurePassword, bool redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, ServerCertificateValidationCallback serverCallback, ClientCertificateRetrievalCallback clientCallback, DbConnectionPool pool, string accessToken, SqlClientOriginalNetworkAddressInfo originalNetworkAddressInfo, bool applyTransientFaultHandling)
    at DbConnectionInternal Microsoft.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
    at DbConnectionInternal Microsoft.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions)
    at DbConnectionInternal Microsoft.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptionsuserOptions, DbConnectionInternal oldConnection)
    at DbConnectionInternal Microsoft.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
    at bool Microsoft.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, uint waitForMultipleObjectsTimeout, bool allowCreate, bool onlyOneCheckConnection, DbConnectionOptions userOptions, out DbConnectionInternal connection)
    at void Microsoft.Data.ProviderBase.DbConnectionPool.WaitForPendingOpen()
@ErikEJ
Copy link
Contributor

ErikEJ commented May 13, 2022

What is your connection string?

@pengweiqhca
Copy link
Author

What is your connection string?

data source=172.17.12.70;initial catalog=BetaUserConfig_DB;user id=BetaUserConfig_DB_Admin;password=xxxxx;TrustServerCertificate=true;

@lcheunglci
Copy link
Contributor

lcheunglci commented May 13, 2022

That looks like a valid connection string, and I tried a similar connection string and it ran through successfully without an issue. However, the code indicated where the exception was thrown shows that FailOverPartner key doesn't exist in the SqlConnectionString, which sounds similar to this #1594 issue where by setting the FailoverPartner to an empty string, it'll will get around this. Otherwise, we could make a check in the userConnectionOptions if it ContainsKey for FailoverPartner first before it checks if the value is null, so it can avoid the key not found exception from being thrown.

@JRahnama
Copy link
Contributor

@pengweiqhca what version of SqlClient are you using?

@pengweiqhca
Copy link
Author

@pengweiqhca what version of SqlClient are you using?

4.1.0

@mark-raymond
Copy link

I'm also hitting this (or rather a customer of ours is). We are using Microsoft.Data.SqlClient 4.1.0. The connection string is Data Source=XXXXX;Initial Catalog=XXXXX;Integrated Security=True;Pooling=False;Trust Server Certificate=True;Application Name="Red Gate Software - SQL Tools"

@lcheunglci
Copy link
Contributor

@pengweiqhca @mark-raymond could try out the fix in the PR #1614 and see if it resolves your issue. The PR is tagged in the upcoming release, but I don't have the test environment with a server with AG to verify it before it can be merged.

@lcheunglci
Copy link
Contributor

@DavoudEshtehari
Copy link
Contributor

@pengweiqhca and @mark-raymond could you verify it with the provided NuGet, please?

@mark-raymond
Copy link

Ah, the issue was hit by a customer of ours, I don't actually have access to the environment myself to test against.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants