Hello, when I click on my new API I get a 500 error in production. However, locally (dev.) it's correct.
log
ERROR 2025-10-08 10:04:13,926 [21 ] .EntityFrameworkCore.Database.Connection - An error occurred using the connection to database '' on server ''.
ERROR 2025-10-08 10:04:13,941 [21 ] Mvc.ExceptionHandling.AbpExceptionFilter - The ConnectionString property has not been initialized.
System.InvalidOperationException: The ConnectionString property has not been initialized.
at Microsoft.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
at Microsoft.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry, SqlConnectionOverrides overrides)
at Microsoft.Data.SqlClient.SqlConnection.InternalOpenAsync(CancellationToken cancellationToken)
--- End of stack trace from previous location ---
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)
at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.BeginTransactionAsync(IsolationLevel isolationLevel, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerExecutionStrategy.ExecuteAsync[TState,TResult](TState state, Func`4 operation, Func`4 verifySucceeded, CancellationToken cancellationToken)
at Abp.EntityFrameworkCore.Uow.DbContextEfCoreTransactionStrategy.CreateDbContextAsync[TDbContext](String connectionString, IDbContextResolver dbContextResolver)
at Abp.EntityFrameworkCore.Uow.EfCoreUnitOfWork.GetOrCreateDbContextAsync[TDbContext](Nullable`1 multiTenancySide, String name)
at Portail_GTC.repository.ControleEARepository.GetControlesAsync() in C:\source\Portail_GTC\Portail_GTC\aspnet-core\src\Portail_GTC.EntityFrameworkCore\repository\ControleEARepository.cs:line 55
at Portail_GTC.EA_ProdA.EAProdAppService.GetAllControleEA(ControleEAInput input) in C:\source\Portail_GTC\Portail_GTC\aspnet-core\src\Portail_GTC.Application\EA_Prod\EAProdAppService.cs:line 40
at lambda_method2982(Closure, Object)
at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.AwaitableObjectResultExecutor.Execute(ActionContext actionContext, IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask`1 actionResultValueTask)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeInnerFilterAsync>g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextExceptionFilterAsync>g__Awaited|26_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
ERROR 2025-10-08 10:04:14,060 [21 ] .EntityFrameworkCore.Database.Connection - An error occurred using the connection to database '' on server ''.
ERROR 2025-10-08 10:04:14,075 [21 ] Mvc.ExceptionHandling.AbpExceptionFilter - The ConnectionString property has not been initialized.
System.InvalidOperationException: The ConnectionString property has not been initialized.
at Microsoft.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
at Microsoft.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry, SqlConnectionOverrides overrides)
at Microsoft.Data.SqlClient.SqlConnection.InternalOpenAsync(CancellationToken cancellationToken)
--- End of stack trace from previous location ---
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)
at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.BeginTransactionAsync(IsolationLevel isolationLevel, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerExecutionStrategy.ExecuteAsync[TState,TResult](TState state, Func`4 operation, Func`4 verifySucceeded, CancellationToken cancellationToken)
at Abp.EntityFrameworkCore.Uow.DbContextEfCoreTransactionStrategy.CreateDbContextAsync[TDbContext](String connectionString, IDbContextResolver dbContextResolver)
at Abp.EntityFrameworkCore.Uow.EfCoreUnitOfWork.GetOrCreateDbContextAsync[TDbContext](Nullable`1 multiTenancySide, String name)
at Portail_GTC.repository.ControleEARepository.GetControlesAsync() in C:\source\Portail_GTC\Portail_GTC\aspnet-core\src\Portail_GTC.EntityFrameworkCore\repository\ControleEARepository.cs:line 55
at Portail_GTC.EA_ProdA.EAProdAppService.GetAllControleEA(ControleEAInput input) in C:\source\Portail_GTC\Portail_GTC\aspnet-core\src\Portail_GTC.Application\EA_Prod\EAProdAppService.cs:line 40
at lambda_method2982(Closure, Object)
at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.AwaitableObjectResultExecutor.Execute(ActionContext actionContext, IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask`1 actionResultValueTask)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeInnerFilterAsync>g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextExceptionFilterAsync>g__Awaited|26_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
ERROR 2025-10-08 10:04:14,099 [21 ] .EntityFrameworkCore.Database.Connection - An error occurred using the connection to database '' on server ''.
ERROR 2025-10-08 10:04:14,108 [21 ] Mvc.ExceptionHandling.AbpExceptionFilter - The ConnectionString property has not been initialized.
System.InvalidOperationException: The ConnectionString property has not been initialized.
at Microsoft.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
at Microsoft.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry, SqlConnectionOverrides overrides)
at Microsoft.Data.SqlClient.SqlConnection.InternalOpenAsync(CancellationToken cancellationToken)
--- End of stack trace from previous location ---
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)
at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.BeginTransactionAsync(IsolationLevel isolationLevel, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerExecutionStrategy.ExecuteAsync[TState,TResult](TState state, Func`4 operation, Func`4 verifySucceeded, CancellationToken cancellationToken)
at Abp.EntityFrameworkCore.Uow.DbContextEfCoreTransactionStrategy.CreateDbContextAsync[TDbContext](String connectionString, IDbContextResolver dbContextResolver)
at Abp.EntityFrameworkCore.Uow.EfCoreUnitOfWork.GetOrCreateDbContextAsync[TDbContext](Nullable`1 multiTenancySide, String name)
at Portail_GTC.repository.ControleEARepository.GetControlesAsync() in C:\source\Portail_GTC\Portail_GTC\aspnet-core\src\Portail_GTC.EntityFrameworkCore\repository\ControleEARepository.cs:line 55
at Portail_GTC.EA_ProdA.EAProdAppService.GetAllControleEA(ControleEAInput input) in C:\source\Portail_GTC\Portail_GTC\aspnet-core\src\Portail_GTC.Application\EA_Prod\EAProdAppService.cs:line 40
at lambda_method2982(Closure, Object)
at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.AwaitableObjectResultExecutor.Execute(ActionContext actionContext, IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask`1 actionResultValueTask)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeInnerFilterAsync>g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextExceptionFilterAsync>g__Awaited|26_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
6 Answer(s)
-
0
Hi @gtc
It seems that the issue is caused by a missing or incorrect connection string configuration.
In the production environment, the API might not be reading the correct
appsettings.Production.jsonfile or theConnectionStringssection might be missing.Please check your configuration file:
"ConnectionStrings": { "Default": "Server=yourserver; Database=yourdb; User Id=xxx; Password=xxx; TrustServerCertificate=True;" }If this section is empty or not defined in the production configuration, the
YourProjectNameDbContextFactorywill receive an empty connection string. Add the correct connection string or ensure it’s being read properly from environment variables.Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
my appsetting-production file is not empty
** PRIVATE INFORMATION IS DELETED FOR SECURITY REASONS **
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
Hi @gtc
If you are hosting the application on IIS, please make sure the environment variable is correctly set inside your web.config file under the
<aspNetCore>element, as shown below:<configuration> <system.webServer> <handlers> <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" /> </handlers> <aspNetCore processPath="dotnet" arguments=".\YourProjectName.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess"> <environmentVariables> <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Production" /> </environmentVariables> </aspNetCore> </system.webServer> </configuration>Related IIS Publish Document
If you are hosting on Azure App Service, verify that there is an application setting named
ASPNETCORE_ENVIRONMENTwith the value set to Production.Related Azure Publish Document
If you are running the application in a Docker container, make sure to include the following environment variable when running the container:
-e ASPNETCORE_ENVIRONMENT=ProductionRelated Docker Publish Document
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
please, despite the changes, I still have the error message. precision, I only have the error with the new API which uses secondbcontext and in production
namespace Portail_GTC.EntityFrameworkCore { public class EA_ProdbContext : AbpDbContext { // Déclare tes tables ici public virtual DbSet<Personne> Personnes { get; set; } public virtual DbSet<ControleEA> ControleEAs { get; set; } public EA_ProdbContext(DbContextOptions<EA_ProdbContext> options) : base(options) { } protected override void OnModelCreating(ModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); } } }```Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
please, despite the changes, I still have the error message. precision, I only have the error with the new API which uses secondbcontext and in production
namespace Portail_GTC.EntityFrameworkCore { public class EA_ProdbContext : AbpDbContext { // Déclare tes tables ici public virtual DbSet<Personne> Personnes { get; set; } public virtual DbSet<ControleEA> ControleEAs { get; set; } public EA_ProdbContext(DbContextOptions<EA_ProdbContext> options) : base(options) { } protected override void OnModelCreating(ModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); } } }```Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
using Abp; using Abp.Dependency; using Abp.EntityFrameworkCore.Configuration; using Abp.Modules; using Abp.OpenIddict.EntityFrameworkCore; using Abp.Reflection.Extensions; using Abp.Zero.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Portail_GTC.Configuration; using Portail_GTC.EntityHistory; using Portail_GTC.Migrations.Seed; using Portail_GTC.repository; using Portail_GTC.Test.Repository; using Portail_GTC.Web; namespace Portail_GTC.EntityFrameworkCore; [DependsOn( typeof(AbpZeroCoreEntityFrameworkCoreModule), typeof(Portail_GTCCoreModule), typeof(AbpZeroCoreOpenIddictEntityFrameworkCoreModule) )] public class Portail_GTCEntityFrameworkCoreModule : AbpModule { /* Used it tests to skip DbContext registration, in order to use in-memory database of EF Core */ public bool SkipDbContextRegistration { get; set; } public bool SkipDbSeed { get; set; } public override void PreInitialize() { if (!SkipDbContextRegistration) { // Configure first DbContext Configuration.Modules.AbpEfCore().AddDbContext<Portail_GTCDbContext>(options => { if (options.ExistingConnection != null) { Portail_GTCDbContextConfigurer.Configure(options.DbContextOptions, options.ExistingConnection); } else { Portail_GTCDbContextConfigurer.Configure(options.DbContextOptions, options.ConnectionString); } }); // Configure EA_prod DbContext Configuration.Modules.AbpEfCore().AddDbContext<EA_ProdbContext>(options => { if (options.ExistingConnection != null) { EA_ProdbContextConfigurer.Configure(options.DbContextOptions, options.ExistingConnection); } else { var configuration = AppConfigurations.Get(WebContentDirectoryFinder.CalculateContentRootFolder(), addUserSecrets: true); EA_ProdbContextConfigurer.Configure(options.DbContextOptions, configuration.GetConnectionString("EA_Prodb")); //EA_ProdbContextConfigurer.Configure(options.DbContextOptions, configuration.GetConnectionString(Portail_GTCConsts.ConnectionEA_Prodb)); } }); // IocManager.Register<IControleEARepository, ControleEARepository>(DependencyLifeStyle.Transient); } // Set this setting to true for enabling entity history. Configuration.EntityHistory.IsEnabled = false; // Uncomment below line to write change logs for the entities below: //Configuration.EntityHistory.Selectors.Add("Portail_GTCEntities", EntityHistoryHelper.TrackedTypes); //Configuration.CustomConfigProviders.Add(new EntityHistoryConfigProvider(Configuration)); } public override void Initialize() { IocManager.RegisterAssemblyByConvention(typeof(Portail_GTCEntityFrameworkCoreModule).GetAssembly()); } public override void PostInitialize() { var configurationAccessor = IocManager.Resolve<IAppConfigurationAccessor>(); using (var scope = IocManager.CreateScope()) { if (!SkipDbSeed && scope.Resolve<DatabaseCheckHelper>() .Exist(configurationAccessor.Configuration["ConnectionStrings:Default"])) { SeedHelper.SeedHostDb(IocManager); } } } }using Abp.Dependency; using Abp.EntityFrameworkCore.Configuration; using Abp.Modules; using Abp.OpenIddict.EntityFrameworkCore; using Abp.Reflection.Extensions; using Abp.Zero.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Portail_GTC.Configuration; using Portail_GTC.EntityHistory; using Portail_GTC.Migrations.Seed; using Portail_GTC.repository; using Portail_GTC.Test.Repository; using Portail_GTC.Web; namespace Portail_GTC.EntityFrameworkCore; [DependsOn( typeof(AbpZeroCoreEntityFrameworkCoreModule), typeof(Portail_GTCCoreModule), typeof(AbpZeroCoreOpenIddictEntityFrameworkCoreModule) )] public class Portail_GTCEntityFrameworkCoreModule : AbpModule { /* Used it tests to skip DbContext registration, in order to use in-memory database of EF Core */ public bool SkipDbContextRegistration { get; set; } public bool SkipDbSeed { get; set; } public override void PreInitialize() { if (!SkipDbContextRegistration) { // Configure first DbContext Configuration.Modules.AbpEfCore().AddDbContext<Portail_GTCDbContext>(options => { if (options.ExistingConnection != null) { Portail_GTCDbContextConfigurer.Configure(options.DbContextOptions, options.ExistingConnection); } else { Portail_GTCDbContextConfigurer.Configure(options.DbContextOptions, options.ConnectionString); } }); // Configure EA_prod DbContext Configuration.Modules.AbpEfCore().AddDbContext<EA_ProdbContext>(options => { if (options.ExistingConnection != null) { EA_ProdbContextConfigurer.Configure(options.DbContextOptions, options.ExistingConnection); } else { var configuration = AppConfigurations.Get(WebContentDirectoryFinder.CalculateContentRootFolder()); EA_ProdbContextConfigurer.Configure(options.DbContextOptions, configuration.GetConnectionString("EA_Prodb")); //EA_ProdbContextConfigurer.Configure(options.DbContextOptions, configuration.GetConnectionString(Portail_GTCConsts.ConnectionEA_Prodb)); } }); // IocManager.Register<IControleEARepository, ControleEARepository>(DependencyLifeStyle.Transient); } // Set this setting to true for enabling entity history. Configuration.EntityHistory.IsEnabled = false; // Uncomment below line to write change logs for the entities below: //Configuration.EntityHistory.Selectors.Add("Portail_GTCEntities", EntityHistoryHelper.TrackedTypes); //Configuration.CustomConfigProviders.Add(new EntityHistoryConfigProvider(Configuration)); } public override void Initialize() { IocManager.RegisterAssemblyByConvention(typeof(Portail_GTCEntityFrameworkCoreModule).GetAssembly()); } public override void PostInitialize() { var configurationAccessor = IocManager.Resolve<IAppConfigurationAccessor>(); using (var scope = IocManager.CreateScope()) { if (!SkipDbSeed && scope.Resolve<DatabaseCheckHelper>() .Exist(configurationAccessor.Configuration["ConnectionStrings:Default"])) { SeedHelper.SeedHostDb(IocManager); } } } }Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image)
