Answer the question
In order to leave comments, you need to log in
Two or more connection and session strings?
There is a simple site that displays some information in descending order from the database tables. There is also a registration system, password change, etc. There was a need to use this site on 2-3 different databases (the same in structure) that lie on different machines. That is, in fact, you need to implement the following: in the header, poke the server 1 button (for example) and receive data from the server 1 database, register, change the password, etc. Near the server 2 button and everything is similar, but with the base, which lies on another server. User authorization is based on Claims and it is important that they are "inside" the connection string they have chosen until they decide to go to another database and click on the appropriate button.
How is this generally implemented and in which direction to dig then? If possible, an example. Thank you all very much for any information!
Answer the question
In order to leave comments, you need to log in
You can make as many string connections as you like in the settings, each with its own name. Make an abstraction over the connection to the database, you will pass the name of the connection there and work with the methods of this abstraction already.
In simple terms, it's like this
<connectionStrings>
<add name="DB1Connection" connectionString="data source=(local);initial catalog=myDB1;" />
<add name="DB2Connection1" connectionString="data source=(local);initial catalog=myDB2;" />
<add name="DB3Connection1" connectionString="data source=(local);initial catalog=myDB3;" />
</connectionStrings>
connectionStringName = "DB3Connection1";
public class MyDbContext : DbContext
{
public MyDbContext(string connectionStringName) : base(connectionStringName)
{ }
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question