private void WriteToSQL(WebBaseEventCollection events, int eventsDiscardedByBuffer, DateTime lastNotificationUtc)
 {
     if (this._retryDate <= DateTime.UtcNow)
     {
         try
         {
             SqlConnectionHolder connection = SqlConnectionHelper.GetConnection(this._sqlConnectionString, true);
             SqlCommand          sqlCommand = new SqlCommand("dbo.aspnet_WebEvent_LogEvent");
             this.CheckSchemaVersion(connection.Connection);
             sqlCommand.CommandType = CommandType.StoredProcedure;
             sqlCommand.Connection  = connection.Connection;
             if (this._commandTimeout > -1)
             {
                 sqlCommand.CommandTimeout = this._commandTimeout;
             }
             this.PrepareParams(sqlCommand);
             try
             {
                 connection.Open(null, true);
                 Interlocked.Increment(ref this._connectionCount);
                 if (eventsDiscardedByBuffer != 0)
                 {
                     WebBaseEvent eventRaised = new WebBaseEvent(System.Web.SR.GetString("Sql_webevent_provider_events_dropped", new object[] { eventsDiscardedByBuffer.ToString(CultureInfo.InstalledUICulture), lastNotificationUtc.ToString("r", CultureInfo.InstalledUICulture) }), null, 0x1771, 0xc47d);
                     this.FillParams(sqlCommand, eventRaised);
                     sqlCommand.ExecuteNonQuery();
                 }
                 foreach (WebBaseEvent event3 in events)
                 {
                     this.FillParams(sqlCommand, event3);
                     sqlCommand.ExecuteNonQuery();
                 }
             }
             finally
             {
                 connection.Close();
                 Interlocked.Decrement(ref this._connectionCount);
             }
             try
             {
                 this.EventProcessingComplete(events);
             }
             catch
             {
             }
         }
         catch
         {
             double num = 30.0;
             if (this._commandTimeout > -1)
             {
                 num = this._commandTimeout;
             }
             this._retryDate = DateTime.UtcNow.AddSeconds(num);
             throw;
         }
     }
 }
 /// <devdoc>
 /// </devdoc>
 internal static SqlConnectionHolder GetConnection(string connectionString, bool revertImpersonation)
 {
     var holder = new SqlConnectionHolder(connectionString);
     var closeConn = true;
     try
     {
         holder.Open(revertImpersonation);
         closeConn = false;
     }
     finally
     {
         if (closeConn)
         {
             holder.Close();
             holder = null;
         }
     }
     return holder;
 }
        internal static SqlConnectionHolder GetConnection(string connectionString)
        {
            var  holder    = new SqlConnectionHolder(connectionString);
            bool closeConn = true;

            try
            {
                holder.Open();
                closeConn = false;
            }
            finally
            {
                if (closeConn)
                {
                    holder.Close();
                    holder = null;
                }
            }
            return(holder);
        }
Beispiel #4
0
        void WriteToSQL(WebBaseEventCollection events, int eventsDiscardedByBuffer, DateTime lastNotificationUtc)
        {
            // We don't want to send any more events until we've waited until the _retryDate (which defaults to minValue)
            if (_retryDate > DateTime.UtcNow)
            {
                return;
            }

            try {
                SqlConnectionHolder sqlConnHolder = SqlConnectionHelper.GetConnection(_sqlConnectionString, true);

                SqlCommand sqlCommand = new SqlCommand(SP_LOG_EVENT);

                CheckSchemaVersion(sqlConnHolder.Connection);

                sqlCommand.CommandType = CommandType.StoredProcedure;
                sqlCommand.Connection  = sqlConnHolder.Connection;

                if (_commandTimeout > -1)
                {
                    sqlCommand.CommandTimeout = _commandTimeout;
                }

                PrepareParams(sqlCommand);

                try {
                    sqlConnHolder.Open(null, true);
                    Interlocked.Increment(ref _connectionCount);

                    if (eventsDiscardedByBuffer != 0)
                    {
                        WebBaseEvent infoEvent = new WebBaseEvent(
                            SR.GetString(SR.Sql_webevent_provider_events_dropped,
                                         eventsDiscardedByBuffer.ToString(CultureInfo.InstalledUICulture),
                                         lastNotificationUtc.ToString("r", CultureInfo.InstalledUICulture)),
                            null,
                            WebEventCodes.WebEventProviderInformation,
                            WebEventCodes.SqlProviderEventsDropped);

                        FillParams(sqlCommand, infoEvent);
                        sqlCommand.ExecuteNonQuery();
                    }

                    foreach (WebBaseEvent eventRaised in events)
                    {
                        FillParams(sqlCommand, eventRaised);
                        sqlCommand.ExecuteNonQuery();
                    }
                }
#if DBG
                catch (Exception e) {
                    Debug.Trace("SqlWebEventProvider", "ExecuteNonQuery failed: " + e);
                    throw;
                }
#endif
                finally {
                    sqlConnHolder.Close();
                    Interlocked.Decrement(ref _connectionCount);
                }

#if (!DBG)
                try {
#endif
                EventProcessingComplete(events);
#if (!DBG)
            }
            catch {
                // Ignore all errors.
            }
#endif
            }
            catch {
                // For any failure, we will wait at least 30 seconds or _commandTimeout before trying again
                double timeout = 30;
                if (_commandTimeout > -1)
                {
                    timeout = (double)_commandTimeout;
                }
                _retryDate = DateTime.UtcNow.AddSeconds(timeout);
                throw;
            }
        }