Re: Duplicated key in connection pool
Posted by: Minh Tran
Date: October 25, 2023 09:08PM

I have the same issue when querying database from api. It happens right after app startup.

An item with the same key has already been added. Key: server=localhost;database=ditech_portal;user id=root;password=<my_password>
System.ArgumentException: An item with the same key has already been added. Key: server=localhost;database=ditech_portal;user id=root;password=<my_password>
at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)
at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
at MySql.Data.MySqlClient.MySqlPoolManager.GetPoolAsync(MySqlConnectionStringBuilder settings, Boolean execAsync, CancellationToken cancellationToken)
at MySql.Data.MySqlClient.MySqlConnection.OpenAsync(Boolean execAsync, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenInternalAsync(Boolean errorsExpected, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenInternalAsync(Boolean errorsExpected, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenAsync(CancellationToken cancellationToken, Boolean errorsExpected)



I'm using MySql.EntityFrameworkCore 7.0.2

here is my dbcontext register code


public static IServiceCollection AddMySqlDbContext(this IServiceCollection services, string connectionString)
{
services.AddDbContext<DiTechPortalDbContext>(options =>
{
options.UseMySQL(connectionString);
});
services.AddScoped<IUnitOfWork, UnitOfWork<DiTechPortalDbContext>>();
return services;
}

Options: ReplyQuote


Subject
Written By
Posted
Re: Duplicated key in connection pool
October 25, 2023 09:08PM


Sorry, only registered users may post in this forum.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.