Forum Discussion

Anirban1795's avatar
Anirban1795
Copper Contributor
Mar 18, 2023

Dyanmically store and retrieve connection strings as configuration from db in.Net 6 Web API

I am using a .Net 6 web api that supports multi-tenancy. 

 

Most of my common connection strings are part of connectionstrings section of appsettings.json file.

 

All my tenants are having separate databases.

 

Is there any way that I can develop a controller that would be able to save and retrieve connection strings as configuration ?

 

Basically these connections strings would be saved by the users of specific tenants. When a code block tries to retrieve all connection strings , the code block should be able to retrieve all connections strings that are saved under connection strings section in appsettings and the connection strings that are saved in tenant DB of the specific tenant. Tenant A should not see the connection strings saved in tenant B database and vice versa.

 

 It seems there should be some way to achieve this using IConfigurationBuilder, but I am not able to figure out how. Please guide me regarding this.

  • playermaker's avatar
    playermaker
    Copper Contributor
    One question for you, how can you get the connection before DBA getting connection string belongs to?
  • Hi Anirban1795,

    Thanks for posting your issue here.

    However this platform is used for how-to discussions and sharing best practices for building any app with .NET.Since your issue is a technical question, welcome to post it in Microsoft Q&A forum, the support team and communities on Microsoft Q&A will help you for any technical questions.
    Besides, it will be appreciated if you can share it here once you post this technical question Microsoft Q&A.
    Best Regards,
    Lan Huang

Resources