Open Closed

Setting the Database Connection String from a KeyVault setting when the environment is Production #981


User avatar
0
jtallon created
  • **ABP Framework version: latest
  • UI type: MVC
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated (Angular): yes

Hi,

Can you please point me in the correct direction to how to configure the database connection string to load from a Key Vault scret (Azure). The part that is causing me the most confusion is how to set the connection string from the Config that is loading from key vault.

I have Configured the Program.cs in the Web project to load settings from kv.

And I have tested to make sure it grabs the values from kv, which seem to be fine.

Lets assume I have a secret called db-string and i want to set the DbConext connection string to that value. How do to get the DbContext to use this connection string?

Regards John


4 Answer(s)
  • User Avatar
    0
    Moyaoxiang created

    Hi @jtallon, You can refer to https://docs.microsoft.com/en-us/aspnet/core/security/key-vault-configuration?view=aspnetcore-5.0#bind-an-array-to-a-class, I think only need to define ConnectionStrings--db-string.

  • User Avatar
    0
    jtallon created

    Thanks for your help @Moyaoxiang, that clears a lot up.

    How can I configure the DbContext to use a specific database connection string config name. By default it used "Default", but I want to tell it to use "Somethingelse" at run time. Not sure of this is an abp config or ef config.

  • User Avatar
    0
    Moyaoxiang created

    Hi jtallon, You can use the ConnectionStringName Attribute. e.g.

    [ConnectionStringName("Default")]
    public class CommercialDemoDbContext : AbpDbContext<CommercialDemoDbContext>
    {
    
    }
    
  • User Avatar
    0
    ServiceBot created
    Support Team Automatic process manager

    This question has been automatically marked as stale because it has not had recent activity.

Made with ❤️ on ABP v9.1.0-preview. Updated on December 10, 2024, 06:38