.NET - users and different databases

I am looking for some users accessing one database and other users accessing another database based on the company to which they belong. What would be the best way to handle connection strings and make sure the user is connected to the correct db at login?

Thanks for any ideas.

+3
source share
3 answers

In Web.Config or App.Config

<connectionStrings>
  <add name="ConnectionForDudes" providerName="System.Data.SqlClient"
      connectionString="Data Source=___MALECONNECTIONHERE___"/>
  <add name="ConnectionForChicks" providerName="System.Data.SqlClient"
      connectionString="Data Source=___FEMALECONNECTIONHERE___"/>
</connectionStrings>

When it's time to open the database, you will get a connection string as follows:

bool UserIsMale = true;
string ConnectionStringName = "ConnectionFor" + UserIsMale ? "Dudes" : "Chicks";
string ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings[ConnectionStringName].ConnectionString;
+7
source

I would use a dynamic link string builder and a main database that maps user accounts to other databases.

, , . Windows, .

+6

There is a database table that stores connection information for each user. Perhaps something like a vendor model would be helpful?

+3
source

Source: https://habr.com/ru/post/1699171/


All Articles