Beispiel #1
0
 /// <summary>
 /// Add a new connection to the configuration context.
 /// </summary>
 /// <param name="connectionName"></param>
 /// <param name="connectionString"></param>
 /// <param name="providerName"></param>
 public static void AddConnectionString(String connectionName, String connectionString, String providerName = null)
 {
     ConnectionStrings.AddOrUpdate(connectionName, connectionString, (name, old) => connectionString);
     if (providerName != null)
     {
         var factory = DatabaseConfigurationContext.GetProviderFactory(providerName);
         DbProviders.AddOrUpdate(connectionName, factory, (name, oldFactory) => factory);
     }
 }
Beispiel #2
0
        /// <summary>
        /// Reads Connection Strings from Web.config or App.config.
        /// </summary>
        public static void ReadFromConfiguration()
        {
            if (ConfigurationManager.ConnectionStrings != null && ConfigurationManager.ConnectionStrings.Count > 0)
            {
                for (int index = 0; index < ConfigurationManager.ConnectionStrings.Count; index++)
                {
                    var connString = ConfigurationManager.ConnectionStrings[index];

                    ConnectionStrings.AddOrUpdate(connString.Name, connString.ConnectionString, (oldString, newString) => newString);

                    DbProviderFactory provider = GetProviderFactory(connString.ProviderName);

                    DbProviders.AddOrUpdate(connString.Name, provider, (name, oldProvider) => provider);
                }
            }
        }