SHARE
TWEET

Untitled

a guest Jun 27th, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?xml version="1.0" encoding="utf-8" ?>
  2. <configuration>
  3.   <appSettings>
  4.     <add key="Environment" value="Home"/>
  5.   </appSettings>
  6.   <connectionStrings>
  7.     <add name="Work" connectionString="..."/>
  8.     <add name="Home" connectionString="..."/>
  9.   </connectionStrings>
  10. </configuration>
  11.      
  12. string environment = ConfigurationManager.AppSettings["Environment"];
  13. ConfigurationManager.ConnectionStrings[environment].ConnectionString;
  14.      
  15. <?xml version="1.0" encoding="utf-8" ?>
  16. <configuration>
  17.     <connectionStrings>
  18.         <add name="HomeEnvironment"
  19.              connectionString="Data Source=**HOME-COMPUTER**SQLEXPRESS;Initial Catalog=**HomeDatabase**;Integrated Security=True;"
  20.              providerName="System.Data.SqlClient" />
  21.         <add name="WorkEnvironment"
  22.              connectionString="DataSource=**WORK-COMPUTER**SQLEXPRESS;Initial Catalog=**WorkDatabase**;Integrated Security=True;"
  23.              providerName="System.Data.SqlClient"/>
  24.     </connectionStrings>
  25. </configuration>
  26.      
  27. var environment = Environment.MachineName == "HOME-COMPUTER" ? "HomeEnvironment" : "WorkEnvironment";
  28. var connectionString = ConfigurationManager.ConnectionStrings[environment].ConnectionString;
  29. var dbContext = new **Databasename**ContextDataContext(connectionString);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top