Example #1
0
        public void TwoTablesNotificationTest()
        {
            const int ChangesCountFirstTable  = 5;
            const int ChangesCountSecondTable = 7;

            var changesReceived1 = 0;
            var changesReceived2 = 0;

            OnChangeEventHandler onChange1 = null;

            onChange1 = (s, e) =>
            {
                if (e != null && e.Info == SqlNotificationInfo.Insert)
                {
                    changesReceived1++;
                }

                using (var connection = new SqlConnection(TEST_CONNECTION_STRING))
                    using (var command1 = new SqlCommand("SELECT TestField FROM dbo.TestTable", connection))
                    {
                        connection.Open();

                        var dep = (SqlDependency)s;
                        if (dep != null)
                        {
                            dep.OnChange -= onChange1;
                        }
                        command1.Notification = null;
                        dep           = new SqlDependency(command1);
                        dep.OnChange += onChange1;
                        command1.ExecuteReader().Close();
                    }
            };

            OnChangeEventHandler onChange2 = null;

            onChange2 = (s, e) =>
            {
                if (e != null && e.Info == SqlNotificationInfo.Insert)
                {
                    changesReceived2++;
                }

                using (var connection = new SqlConnection(TEST_CONNECTION_STRING))
                    using (var command2 = new SqlCommand("SELECT TestField FROM dbo.TestTable2", connection))
                    {
                        connection.Open();

                        var dep = (SqlDependency)s;
                        if (dep != null)
                        {
                            dep.OnChange -= onChange2;
                        }
                        command2.Notification = null;
                        dep           = new SqlDependency(command2);
                        dep.OnChange += onChange2;
                        command2.ExecuteReader().Close();
                    }
            };

            SqlDependency.Start(TEST_CONNECTION_STRING);

            onChange1(null, null);

            SqlDependency.Start(TEST_CONNECTION_STRING);

            onChange2(null, null);

            MakeTableInsertChange(ChangesCountFirstTable);
            MakeTableInsertChange(ChangesCountSecondTable, TEST_TABLE_NAME_2);

            Assert.AreEqual(ChangesCountFirstTable, changesReceived1);
            Assert.AreEqual(ChangesCountSecondTable, changesReceived2);

            SqlDependency.Stop(TEST_CONNECTION_STRING);
        }
Example #2
0
 public void Dispose()
 {
     SqlDependency.Stop(ConnectHelper.ConnectConnectionString(), "SPMConnectClientsQueue");
 }
 protected void Application_End()
 {
     //Stop SQL dependency
     SqlDependency.Stop(con);
 }
 public void StopNotification()
 {
     SqlDependency.Stop(this.ConnectionString, "ChangeTaskAndMessage");
 }
Example #5
0
 public void TerminateDependency()
 {
     // Release the dependency.
     SqlDependency.Stop(GC.ConnectionString);
 }
Example #6
0
 protected void Application_End()
 {
     //here we will stop Sql Dependency
     SqlDependency.Stop(con);
 }
Example #7
0
 void Application_End(object sender, EventArgs e)
 {
     SqlDependency.Stop(ConfigurationManager.ConnectionStrings["CONNECTION_STRING"].ConnectionString);
 }
 protected void Application_End(object sender, EventArgs e)
 {
     //here we will stop Sql Dependency
     SqlDependency.Stop(con);
 }
Example #9
0
 void Termination()
 {
     // Release the dependency.
     SqlDependency.Stop(@"Data Source=BEK-47674357\sqlexpress;Initial Catalog=NotificationList;Integrated Security=True");
 }
Example #10
0
 public void Stop()
 {
     SqlDependency.Stop(this.connectionString, sqlQueue);
 }
Example #11
0
 public void Dispose()
 {
     SqlDependency.Stop(m_ConnectionString);
 }
Example #12
0
 void Application_End(object sender, EventArgs e)
 {
     //  Code that runs on application shutdown
     SqlDependency.Stop(ConfigurationManager.ConnectionStrings["Listened"].ConnectionString);
 }
        public void SqlDepdencyStopNullConnectionString_Throws()
        {
            SqlDependency         sqlDependency = new SqlDependency();
            ArgumentNullException ex            = Assert.Throws <ArgumentNullException>(() => SqlDependency.Stop(null, null));

            Assert.Contains("connectionstring", ex.Message, StringComparison.OrdinalIgnoreCase);
        }
Example #14
0
 public void Dispose()
 {
     // reset event handlers
     SqlDependency.Stop(this.ConnectionString);
 }
Example #15
0
 protected void Application_End()
 {
     //Free the dependency
     SqlDependency.Stop(ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString);
 }
Example #16
0
 public static void broker_stop()
 {
     SqlDependency.Stop(connectionString);
     dependency.OnChange -= broker_wykryl_zmiane;
     dependency           = null;
 }
Example #17
0
 /// <summary>
 /// Stop all event listeners to the SQL database
 /// </summary>
 public static void DependencyTermination()
 {
     SqlDependency.Stop(connectionString);
 }
Example #18
0
        protected void Application_End()
        {
            string CONNECTION_STRING = EMS.Utility.Web.ConfigurationHelper.GetConnectionString(Default_ConnectionName);//System.Configuration.ConfigurationManager.ConnectionStrings["AirWaveDB"].ConnectionString;

            SqlDependency.Stop(CONNECTION_STRING);
        }
Example #19
0
 private void THONGTIN_FormClosing(object sender, FormClosingEventArgs e)
 {
     SqlDependency.Stop(m_connect);
 }
Example #20
0
 /// <summary>
 /// 开始监视
 /// </summary>
 public static void Start(string connectionString)
 {
     SqlServerOnChangeNotice.connectionString = connectionString;
     SqlDependency.Stop(connectionString);
     SqlDependency.Start(connectionString);
 }
Example #21
0
        protected virtual void SqlDependency_OnChange(SqlNotificationEventArgs e, Action <IDataRecord, DbOperation> processRecord)
        {
            Trace.TraceInformation("{0}SQL notification change fired", TracePrefix);

            lock (_stopLocker)
            {
                if (_disposing)
                {
                    return;
                }
            }

            var previousState = Interlocked.CompareExchange(ref _notificationState,
                                                            NotificationState.NotificationReceived, NotificationState.ProcessingUpdates);

            if (previousState == NotificationState.NotificationReceived)
            {
                Trace.TraceError("{0}Overlapping SQL change notifications received, this should never happen, BUG!", TracePrefix);

                return;
            }
            if (previousState == NotificationState.ProcessingUpdates)
            {
                // We're still in the original receive loop

                // New updates will be retreived by the original reader thread
                Trace.TraceVerbose("{0}Original reader processing is still in progress and will pick up the changes", TracePrefix);

                return;
            }

            // _notificationState wasn't ProcessingUpdates (likely AwaitingNotification)

            // Check notification args for issues
            if (e.Type == SqlNotificationType.Change)
            {
                if (e.Info == SqlNotificationInfo.Update)
                {
                    Trace.TraceVerbose("{0}SQL notification details: Type={1}, Source={2}, Info={3}", TracePrefix, e.Type, e.Source, e.Info);
                }
                else if (e.Source == SqlNotificationSource.Timeout)
                {
                    Trace.TraceVerbose("{0}SQL notification timed out", TracePrefix);
                }
                else
                {
                    Trace.TraceError("{0}Unexpected SQL notification details: Type={1}, Source={2}, Info={3}", TracePrefix, e.Type, e.Source, e.Info);

                    Faulted(new SqlMessageBusException(String.Format(CultureInfo.InvariantCulture, Resources.Error_UnexpectedSqlNotificationType, e.Type, e.Source, e.Info)));
                }
            }
            else if (e.Type == SqlNotificationType.Subscribe)
            {
                Debug.Assert(e.Info != SqlNotificationInfo.Invalid, "Ensure the SQL query meets the requirements for query notifications at http://msdn.microsoft.com/en-US/library/ms181122.aspx");

                Trace.TraceError("{0}SQL notification subscription error: Type={1}, Source={2}, Info={3}", TracePrefix, e.Type, e.Source, e.Info);

                if (e.Info == SqlNotificationInfo.TemplateLimit)
                {
                    // We've hit a subscription limit, pause for a bit then start again
                    Thread.Sleep(2000);
                }
                else
                {
                    // Unknown subscription error, let's stop using query notifications
                    _notificationState = NotificationState.Disabled;
                    try
                    {
                        SqlDependency.Stop(ConnectionString);
                    }
                    catch (Exception) { }
                }
            }

            Changed();
        }
Example #22
0
 /// <summary>
 /// 结束监视
 /// </summary>
 public static void Stop()
 {
     SqlDependency.Stop(connectionString);
 }
Example #23
0
 protected void Application_End()
 {
     SqlDependency.Stop(connString);
 }
Example #24
0
 protected void Application_End()
 {
     SqlDependency.Stop(ConfigurationManager.ConnectionStrings["StrConnection"].ConnectionString);
 }
 internal override void OnFinalUnsubscribe()
 {
     SqlDependency.Stop(base.ConnectionString);
     base.OnFinalUnsubscribe();
 }
Example #26
0
 void Termination()
 {
     // Release the dependency.
     SqlDependency.Stop(connectionString, queueName);
 }