Reputation: 19
I am encountering an issue while attempting to connect to a PostgreSQL Pgpool server using Entity Framework Core. The setup involves the utilization of the Postgresql HA Helm Chart by Bitnami, which sets up a high-availability PostgreSQL cluster. The intended behavior is for EF Core to create the database if it doesn't already exist and subsequently migrate data. However, upon initiating the connection and migration process, I am immediately confronted with the following error:
Npgsql.PostgresException (0x80004005): XX000: unable to get session context.
My architecture comprises a PostgreSQL Pgpool server orchestrated via the Bitnami Postgresql HA Helm Chart. The primary goal is to establish a connection using Entity Framework Core and perform migrations to set up the initial data structure. Regrettably, the encountered error is impeding progress.
Ideally, when EF Core connects to the PostgreSQL Pgpool server, it should be able to acquire the necessary session context to proceed with database operations, including database creation and data migration.
Steps Taken:
Configured the PostgreSQL Pgpool server using the Bitnami Postgresql HA Helm Chart. Attempted to connect to the database and initiate data migration using Entity Framework Core. Encountered the Npgsql.PostgresException with the error message indicating a failure to obtain the session context (XX000: unable to get session context).
This is how I am trying to initialize the DbContext in my Startup :
services.AddDbContext<MyDbContext>(options =>
{
options.UseNpgsql(configuration.GetConnectionString("PostgresConnection"))
.UseSnakeCaseNamingConvention();
});
Additional Information:
EF Core Version: 6.0
Upvotes: 1
Views: 908
Reputation: 1
The error message "unable to get session context" has happened to me because the connection string in the configuration.GetConnectionString("PostgresConnection")
method was not correctly configured.
Upvotes: 0
Reputation: 1
I had same issue using docker-compose. My issue turned out to be caused by a missing database. Looking at the logs of the pgpool instance offered some clues.
Upvotes: 0