connect to a DB sql server selected at run time [closed]

-1

I have a web app, which needs to connect to a bd sql server. This is achieved through the typical definition determined in conecctionstring in app.config. I need to be able to have a list of connectionstrmgs (definitions) in order to be able to pass from one to another at the moment of the connection to the bd. this in time of execution. something like a list of databases (servers) to choose from at a given time. Can this be done?

    
asked by Luis Gabriel Fabres 10.12.2017 в 15:40
source

1 answer

0

You can do it in App.config in the following way:

Instead of putting the property as Connection String , you leave it as String and you are separating all the connections with some separator, for example '#' , it must be a separator that does not exist in the connections, so your You can choose which one.

Then we would leave it in the following way:

Data Source=Server1;Initial Catalog=DataBase1;User id=User1;Password=Pass1;#Data Source=Server2;Initial Catalog=DataBase2;User id=User2;Password=Pass2;#Data Source=Server3;Initial Catalog=DataBase3;User id=User3;Password=Pass3;...

Then when you start the application you make a Split of this String and it will return a list (string []) of connection strings:

VariableAppConfigConexiones.Split('#')
    
answered by 11.12.2017 / 09:12
source