private static ConnectionStringSettings GetConnectionStringSettings(string connectionStringName) { var settings = CrmConfigurationManager.CreateConnectionStringSettings(connectionStringName); if (settings == null) { throw new ConfigurationErrorsException("Unable to find a connection string with the name '{0}'.".FormatWith(connectionStringName)); } return(settings); }
/// <summary> /// Initializes the provider with the property values specified in the ASP.NET application's configuration file. /// </summary> public override void Initialize(string name, NameValueCollection config) { if (_initialized) { return; } config.ThrowOnNull("config"); if (string.IsNullOrEmpty(name)) { name = GetType().FullName; } if (string.IsNullOrEmpty(config["description"])) { config["description"] = "Windows Live Id Membership Provider"; } base.Initialize(name, config); ApplicationName = config["applicationName"] ?? Utility.GetDefaultApplicationName(); var connectionStringName = config["connectionStringName"]; var contextName = config["contextName"]; if (!string.IsNullOrWhiteSpace(connectionStringName)) { ConnectionStringName = connectionStringName; } else if (!string.IsNullOrWhiteSpace(contextName)) { ConnectionStringName = CrmConfigurationManager.GetConnectionStringNameFromContext(contextName); } else if (CrmConfigurationManager.CreateConnectionStringSettings(connectionStringName) != null) { ConnectionStringName = name; } else { ConnectionStringName = CrmConfigurationManager.GetConnectionStringNameFromContext(name, true); } if (string.IsNullOrEmpty(ConnectionStringName)) { throw new ConfigurationErrorsException("One of 'connectionStringName' or 'contextName' must be specified on the '{0}' named '{1}'.".FormatWith(this, name)); } LiveIdConnectionStringName = config["liveIdConnectionStringName"]; if (string.IsNullOrEmpty(LiveIdConnectionStringName)) { throw new ConfigurationErrorsException("The 'liveIdConnectionStringName' must be specified on the '{0}' named '{1}'.".FormatWith(this, name)); } var parameters = LiveIdConnectionStringName.ToDictionaryFromConnectionStringName(); AppId = parameters.FirstNotNullOrEmpty("AppId", "Application Id", "ApplicationId"); // Remove all of the known configuration values. If there are any left over, they are unrecognized. config.Remove("name"); config.Remove("applicationName"); config.Remove("contextName"); config.Remove("connectionStringName"); config.Remove("liveIdConnectionStringName"); if (config.Count > 0) { string unrecognizedAttribute = config.GetKey(0); if (!string.IsNullOrEmpty(unrecognizedAttribute)) { throw new ConfigurationErrorsException("The '{0}' named '{1}' does not currently recognize or support the attribute '{2}'.".FormatWith(this, name, unrecognizedAttribute)); } } _initialized = true; }
/// <summary> /// Builds a connection string dictionary from a named configuration connection string. /// </summary> /// <param name="connectionStringName"></param> /// <returns></returns> public static IDictionary <string, string> ToDictionaryFromConnectionStringName(this string connectionStringName) { return(ToDictionary(CrmConfigurationManager.CreateConnectionStringSettings(connectionStringName))); }