Пример #1
0
        public override void Initialize(string name, NameValueCollection config)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }

            base.Initialize(name, config);

            applicationName = GetStringConfigValue(config, "applicationName", "/");
            string connectionStringName = config ["connectionStringName"];

            if (applicationName.Length > 256)
            {
                throw new ProviderException("The ApplicationName attribute must be 256 characters long or less.");
            }
            if (connectionStringName == null || connectionStringName.Length == 0)
            {
                throw new ProviderException("The ConnectionStringName attribute must be present and non-zero length.");
            }

            // XXX check connectionStringName and commandTimeout

            connectionString = WebConfigurationManager.ConnectionStrings [connectionStringName];
            if (connectionString == null)
            {
                throw new ProviderException(String.Format("The connection name '{0}' was not found in the applications configuration or the connection string is empty.", connectionStringName));
            }
            factory = String.IsNullOrEmpty(connectionString.ProviderName) ?
                      System.Data.SqlClient.SqlClientFactory.Instance :
                      ProvidersHelper.GetDbProviderFactory(connectionString.ProviderName);
        }