Dynamic Connection String Scenario

Ömer Karagülmez asked on May 24, 2024 12:00

Hello,

We are required to use “CyberArk .NET Application Password SDK” tool for fetch the db password from a key store. (It’s a bank client)

They sent to us a dll file for using GetPassword() method. And the database password will change every 2-3 days.

Currently CMSConnectionString (in appsettings) value is empty and I filled on application build phase (Startup -> ConfigureService).

But it returns below error:

Error image

So, How can I connect xperience database in runtime?

King regards

Recent Answers


Elmar Höfinghoff answered on May 29, 2024 10:37

Idea: Write a middleware for a connectionstring.config file and refer to it in the appsettings. This could help getting this on the fly. You should avoid to call the DLL method on every request.

0 votesVote for this answer Mark as a Correct answer

Ömer Karagülmez answered on May 30, 2024 13:25 (last edited on May 30, 2024 13:27)

Currently, I don't use appsettings.json for storing the connection string.

I invoke "AddInMemoryCollection" method in program.cs and pass config key ("ConnectionStrings:CMSConnectionString") as parameter.

Even if use appsettings or memory-collection it doesn't work. I can access configuration object in middlewares and I can change the connection string. But application doesn't effect from this. Just works correctly when i restart.

0 votesVote for this answer Mark as a Correct answer

Elmar Höfinghoff answered on May 31, 2024 09:41

Have you tried something like "ConfigurationManager.RefreshSection("connectionStrings")"?

0 votesVote for this answer Mark as a Correct answer

Ömer Karagülmez answered on May 31, 2024 11:47

The application isn't .NET Framework. It's Dotnet 5 application (Live Site). Even I've tried writing "custom configuration provider" and "reloading application configs in a middleware" but it doesn't work.

I think only solution is restarting application

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.