Exemplo n.º 1
0
        /// <summary>
        /// Creates a new <see cref="SqlTraceListener"/> using the specified settings name
        /// </summary>
        /// <param name="settingsName">the name of the SqlTraceListener settings to use from configuration</param>
        public SqlTraceListener(string settingsName)
            : base(settingsName)
        {
            UkadcDiagnosticsSection ukadcDiagnosticsSection = UkadcDiagnosticsSection.ReadConfigSection();
            SqlTraceListenerElement sqlTraceListenerElement = ukadcDiagnosticsSection.SqlTraceListeners[settingsName];
            if (null == sqlTraceListenerElement)
            {
                throw new ConfigurationErrorsException(
                    string.Format(CultureInfo.CurrentCulture, Resources.SqlTraceListenerConfigError, settingsName));
            }

            string connectionString =
                ConfigurationManager.ConnectionStrings[sqlTraceListenerElement.ConnectionStringName].ConnectionString;

            // use default data adapter
            IDataAccessAdapter adapter = new SqlDataAccessAdapter();
            adapter.Initialize(
                connectionString,
                sqlTraceListenerElement.CommandText,
                sqlTraceListenerElement.CommandType);
            DataAccessAdapter = adapter;

            IPropertyReaderFactory readerFactory = DefaultServiceLocator.GetService<IPropertyReaderFactory>();

            foreach (ParameterElement param in sqlTraceListenerElement.Parameters)
            {
                PropertyReader propertyReader = readerFactory.Create(param);

                this.Parameters.Add(
                    new SqlTraceParameter(param.Name, propertyReader, param.CallToString));
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a new <see cref="SqlTraceListener"/> using the specified settings name
        /// </summary>
        /// <param name="settingsName">the name of the SqlTraceListener settings to use from configuration</param>
        public SqlTraceListener(string settingsName)
            : base(settingsName)
        {
            UkadcDiagnosticsSection ukadcDiagnosticsSection = UkadcDiagnosticsSection.ReadConfigSection();
            SqlTraceListenerElement sqlTraceListenerElement = ukadcDiagnosticsSection.SqlTraceListeners[settingsName];

            if (null == sqlTraceListenerElement)
            {
                throw new ConfigurationErrorsException(
                          string.Format(CultureInfo.CurrentCulture, Resources.SqlTraceListenerConfigError, settingsName));
            }

            string connectionString =
                ConfigurationManager.ConnectionStrings[sqlTraceListenerElement.ConnectionStringName].ConnectionString;

            // use default data adapter
            IDataAccessAdapter adapter = new SqlDataAccessAdapter();

            adapter.Initialize(
                connectionString,
                sqlTraceListenerElement.CommandText,
                sqlTraceListenerElement.CommandType);
            DataAccessAdapter = adapter;

            IPropertyReaderFactory readerFactory = DefaultServiceLocator.GetService <IPropertyReaderFactory>();

            foreach (ParameterElement param in sqlTraceListenerElement.Parameters)
            {
                PropertyReader propertyReader = readerFactory.Create(param);

                this.Parameters.Add(
                    new SqlTraceParameter(param.Name, propertyReader, param.CallToString));
            }
        }