예제 #1
0
        internal static string GetConnectionString(NameValueCollection config)
        {
            Debug.Assert(config != null);

            string connectionString = config["connectionString"];

            if (!String.IsNullOrEmpty(connectionString))
            {
                return(connectionString);
            }
            else
            {
                string connectionStringName = config["connectionStringName"];
                if (String.IsNullOrEmpty(connectionStringName))
                {
                    throw new ProviderException(SR.GetString(SR.Connection_name_not_specified));
                }

                connectionString = SqlConnectionHelper.GetConnectionString(connectionStringName, lookupConnectionString: true, appLevel: true);
                if (String.IsNullOrEmpty(connectionString))
                {
                    throw new ProviderException(SR.GetString(SR.Connection_string_not_found, connectionStringName));
                }
                else
                {
                    return(connectionString);
                }
            }
        }
        internal static void InitPolling(string database)
        {
            SqlCacheDependencySection sqlCacheDependency = RuntimeConfig.GetAppConfig().SqlCacheDependency;

            if (!sqlCacheDependency.Enabled)
            {
                throw new ConfigurationErrorsException(System.Web.SR.GetString("Polling_not_enabled_for_sql_cache"), sqlCacheDependency.ElementInformation.Properties["enabled"].Source, sqlCacheDependency.ElementInformation.Properties["enabled"].LineNumber);
            }
            SqlCacheDependencyDatabase databaseConfig = GetDatabaseConfig(database);

            if (databaseConfig.PollTime == 0)
            {
                throw new ConfigurationErrorsException(System.Web.SR.GetString("Polltime_zero_for_database_sql_cache", new object[] { database }), databaseConfig.ElementInformation.Properties["pollTime"].Source, databaseConfig.ElementInformation.Properties["pollTime"].LineNumber);
            }
            if (!s_DatabaseNotifStates.ContainsKey(database))
            {
                string connection = SqlConnectionHelper.GetConnectionString(databaseConfig.ConnectionStringName, true, true);
                if ((connection == null) || (connection.Length < 1))
                {
                    throw new ConfigurationErrorsException(System.Web.SR.GetString("Connection_string_not_found", new object[] { databaseConfig.ConnectionStringName }), databaseConfig.ElementInformation.Properties["connectionStringName"].Source, databaseConfig.ElementInformation.Properties["connectionStringName"].LineNumber);
                }
                lock (s_DatabaseNotifStates)
                {
                    if (!s_DatabaseNotifStates.ContainsKey(database))
                    {
                        DatabaseNotifState state;
                        state = new DatabaseNotifState(database, connection, databaseConfig.PollTime)
                        {
                            _timer = new Timer(s_timerCallback, state, 0, databaseConfig.PollTime)
                        };
                        s_DatabaseNotifStates.Add(database, state);
                    }
                }
            }
        }
예제 #3
0
        public async Task <DataSet> ExecuteDataSet(string procedureName, IDictionary <string, object> values = null)
        {
            DataSet dataSet = null;

            using (var connection = new SqlConnection(_connectionHelper.GetConnectionString()))
            {
                var procedure = CreateProcedure(procedureName, values);
                procedure.Connection = connection;
                connection.Open();
                var adapter = new SqlDataAdapter(procedure);
                dataSet = new DataSet();
                await Task.FromResult(adapter.Fill(dataSet));
            }

            return(dataSet);
        }
예제 #4
0
        public override void Initialize(string name, NameValueCollection config)
        {
            Debug.Trace("SqlWebEventProvider", "Initializing: name=" + name);
            _SchemaVersionCheck = 0;
            string temp = null;

            ProviderUtil.GetAndRemoveStringAttribute(config, "connectionStringName", name, ref temp);
            ProviderUtil.GetAndRemoveStringAttribute(config, "connectionString", name, ref _sqlConnectionString);
            if (!String.IsNullOrEmpty(temp))
            {
                if (!String.IsNullOrEmpty(_sqlConnectionString))
                {
                    throw new ConfigurationErrorsException(SR.GetString(SR.Only_one_connection_string_allowed));
                }

                _sqlConnectionString = SqlConnectionHelper.GetConnectionString(temp, true, true);
                if (_sqlConnectionString == null || _sqlConnectionString.Length < 1)
                {
                    throw new ConfigurationErrorsException(SR.GetString(SR.Connection_string_not_found, temp));
                }
            }
            else
            {
                // If a connection string is specified explicitly, verify that its not using integrated security
                SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(_sqlConnectionString);
                if (builder.IntegratedSecurity)
                {
                    throw new ConfigurationErrorsException(SR.GetString(SR.Cannot_use_integrated_security));
                }
            }

            if (String.IsNullOrEmpty(_sqlConnectionString))
            {
                throw new ConfigurationErrorsException(SR.GetString(SR.Must_specify_connection_string_or_name, temp));
            }


            ProviderUtil.GetAndRemovePositiveOrInfiniteAttribute(config, "maxEventDetailsLength", name, ref _maxEventDetailsLength);
            if (_maxEventDetailsLength == ProviderUtil.Infinite)
            {
                _maxEventDetailsLength = NO_LIMIT;
            }
            else if (_maxEventDetailsLength > SQL_MAX_NTEXT_SIZE)
            {
                throw new ConfigurationErrorsException(SR.GetString(SR.Invalid_max_event_details_length, name, _maxEventDetailsLength.ToString(CultureInfo.CurrentCulture)));
            }

            ProviderUtil.GetAndRemovePositiveAttribute(config, "commandTimeout", name, ref _commandTimeout);

            base.Initialize(name, config);
        }
예제 #5
0
        public override void Initialize(string name, NameValueCollection configSettings)
        {
            HttpRuntime.CheckAspNetHostingPermission(AspNetHostingPermissionLevel.Low, "Feature_not_supported_at_this_level");
            if (configSettings == null)
            {
                throw new ArgumentNullException("configSettings");
            }
            if (string.IsNullOrEmpty(name))
            {
                name = "SqlPersonalizationProvider";
            }
            if (string.IsNullOrEmpty(configSettings["description"]))
            {
                configSettings.Remove("description");
                configSettings.Add("description", System.Web.SR.GetString("SqlPersonalizationProvider_Description"));
            }
            base.Initialize(name, configSettings);
            this._SchemaVersionCheck = 0;
            this._applicationName    = configSettings["applicationName"];
            if (this._applicationName != null)
            {
                configSettings.Remove("applicationName");
                if (this._applicationName.Length > 0x100)
                {
                    object[] args = new object[] { 0x100.ToString(CultureInfo.CurrentCulture) };
                    throw new ProviderException(System.Web.SR.GetString("PersonalizationProvider_ApplicationNameExceedMaxLength", args));
                }
            }
            string str = configSettings["connectionStringName"];

            if (string.IsNullOrEmpty(str))
            {
                throw new ProviderException(System.Web.SR.GetString("PersonalizationProvider_NoConnection"));
            }
            configSettings.Remove("connectionStringName");
            string str2 = SqlConnectionHelper.GetConnectionString(str, true, true);

            if (string.IsNullOrEmpty(str2))
            {
                throw new ProviderException(System.Web.SR.GetString("PersonalizationProvider_BadConnection", new object[] { str }));
            }
            this._connectionString = str2;
            this._commandTimeout   = SecUtility.GetIntValue(configSettings, "commandTimeout", -1, true, 0);
            configSettings.Remove("commandTimeout");
            if (configSettings.Count > 0)
            {
                string key = configSettings.GetKey(0);
                throw new ProviderException(System.Web.SR.GetString("PersonalizationProvider_UnknownProp", new object[] { key, name }));
            }
        }
        public override void Initialize(string name, NameValueCollection config)
        {
            this._SchemaVersionCheck = 0;
            string val = null;

            ProviderUtil.GetAndRemoveStringAttribute(config, "connectionStringName", name, ref val);
            ProviderUtil.GetAndRemoveStringAttribute(config, "connectionString", name, ref this._sqlConnectionString);
            if (!string.IsNullOrEmpty(val))
            {
                if (!string.IsNullOrEmpty(this._sqlConnectionString))
                {
                    throw new ConfigurationErrorsException(System.Web.SR.GetString("Only_one_connection_string_allowed"));
                }
                this._sqlConnectionString = SqlConnectionHelper.GetConnectionString(val, true, true);
                if ((this._sqlConnectionString == null) || (this._sqlConnectionString.Length < 1))
                {
                    throw new ConfigurationErrorsException(System.Web.SR.GetString("Connection_string_not_found", new object[] { val }));
                }
            }
            else
            {
                SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(this._sqlConnectionString);
                if (builder.IntegratedSecurity)
                {
                    throw new ConfigurationErrorsException(System.Web.SR.GetString("Cannot_use_integrated_security"));
                }
            }
            if (string.IsNullOrEmpty(this._sqlConnectionString))
            {
                throw new ConfigurationErrorsException(System.Web.SR.GetString("Must_specify_connection_string_or_name", new object[] { val }));
            }
            ProviderUtil.GetAndRemovePositiveOrInfiniteAttribute(config, "maxEventDetailsLength", name, ref this._maxEventDetailsLength);
            if (this._maxEventDetailsLength == 0x7fffffff)
            {
                this._maxEventDetailsLength = -1;
            }
            else if (this._maxEventDetailsLength > 0x3fffffff)
            {
                throw new ConfigurationErrorsException(System.Web.SR.GetString("Invalid_max_event_details_length", new object[] { name, this._maxEventDetailsLength.ToString(CultureInfo.CurrentCulture) }));
            }
            ProviderUtil.GetAndRemovePositiveAttribute(config, "commandTimeout", name, ref this._commandTimeout);
            base.Initialize(name, config);
        }
        internal static string GetConnectionString(NameValueCollection config)
        {
            string str = config["connectionString"];

            if (string.IsNullOrEmpty(str))
            {
                string str2 = config["connectionStringName"];
                if (string.IsNullOrEmpty(str2))
                {
                    throw new ProviderException(System.Web.SR.GetString("Connection_name_not_specified"));
                }
                bool lookupConnectionString = true;
                bool appLevel = true;
                str = SqlConnectionHelper.GetConnectionString(str2, lookupConnectionString, appLevel);
                if (string.IsNullOrEmpty(str))
                {
                    throw new ProviderException(System.Web.SR.GetString("Connection_string_not_found", new object[] { str2 }));
                }
            }
            return(str);
        }
예제 #8
0
        public override void Initialize(string name, NameValueCollection configSettings)
        {
            HttpRuntime.CheckAspNetHostingPermission(AspNetHostingPermissionLevel.Low, SR.Feature_not_supported_at_this_level);

            // configSettings cannot be null because there are required settings needed below
            if (configSettings == null)
            {
                throw new ArgumentNullException("configSettings");
            }

            if (String.IsNullOrEmpty(name))
            {
                name = "SqlPersonalizationProvider";
            }

            // description will be set from the base class' Initialize method
            if (string.IsNullOrEmpty(configSettings["description"]))
            {
                configSettings.Remove("description");
                configSettings.Add("description", SR.GetString(SR.SqlPersonalizationProvider_Description));
            }
            base.Initialize(name, configSettings);

            _SchemaVersionCheck = 0;

            // If not available, the default value is set in the get accessor of ApplicationName
            _applicationName = configSettings["applicationName"];
            if (_applicationName != null)
            {
                configSettings.Remove("applicationName");

                if (_applicationName.Length > maxStringLength)
                {
                    throw new ProviderException(SR.GetString(SR.PersonalizationProvider_ApplicationNameExceedMaxLength, maxStringLength.ToString(CultureInfo.CurrentCulture)));
                }
            }

            string connectionStringName = configSettings["connectionStringName"];

            if (String.IsNullOrEmpty(connectionStringName))
            {
                throw new ProviderException(SR.GetString(SR.PersonalizationProvider_NoConnection));
            }
            configSettings.Remove("connectionStringName");

            string connectionString = SqlConnectionHelper.GetConnectionString(connectionStringName, true, true);

            if (String.IsNullOrEmpty(connectionString))
            {
                throw new ProviderException(SR.GetString(SR.PersonalizationProvider_BadConnection, connectionStringName));
            }
            _connectionString = connectionString;

            _commandTimeout = SecUtility.GetIntValue(configSettings, "commandTimeout", -1, true, 0);
            configSettings.Remove("commandTimeout");

            if (configSettings.Count > 0)
            {
                string invalidAttributeName = configSettings.GetKey(0);
                throw new ProviderException(SR.GetString(SR.PersonalizationProvider_UnknownProp, invalidAttributeName, name));
            }
        }