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

            Assert.Contains("connectionstring", ex.Message, StringComparison.OrdinalIgnoreCase);
        }
コード例 #14
0
ファイル: DatabaseUtil.cs プロジェクト: rurdea/NetChat
 public void Dispose()
 {
     // reset event handlers
     SqlDependency.Stop(this.ConnectionString);
 }
コード例 #15
0
 protected void Application_End()
 {
     //Free the dependency
     SqlDependency.Stop(ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString);
 }
コード例 #16
0
 public static void broker_stop()
 {
     SqlDependency.Stop(connectionString);
     dependency.OnChange -= broker_wykryl_zmiane;
     dependency           = null;
 }
コード例 #17
0
 /// <summary>
 /// Stop all event listeners to the SQL database
 /// </summary>
 public static void DependencyTermination()
 {
     SqlDependency.Stop(connectionString);
 }
コード例 #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);
        }
コード例 #19
0
ファイル: THONGTIN.cs プロジェクト: nhattan-dev/CHUNGKHOANG
 private void THONGTIN_FormClosing(object sender, FormClosingEventArgs e)
 {
     SqlDependency.Stop(m_connect);
 }
コード例 #20
0
 /// <summary>
 /// 开始监视
 /// </summary>
 public static void Start(string connectionString)
 {
     SqlServerOnChangeNotice.connectionString = connectionString;
     SqlDependency.Stop(connectionString);
     SqlDependency.Start(connectionString);
 }
コード例 #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();
        }
コード例 #22
0
 /// <summary>
 /// 结束监视
 /// </summary>
 public static void Stop()
 {
     SqlDependency.Stop(connectionString);
 }
コード例 #23
0
 protected void Application_End()
 {
     SqlDependency.Stop(connString);
 }
コード例 #24
0
ファイル: Global.asax.cs プロジェクト: hchavez98/SiiceFinal
 protected void Application_End()
 {
     SqlDependency.Stop(ConfigurationManager.ConnectionStrings["StrConnection"].ConnectionString);
 }
コード例 #25
0
 internal override void OnFinalUnsubscribe()
 {
     SqlDependency.Stop(base.ConnectionString);
     base.OnFinalUnsubscribe();
 }
コード例 #26
0
 void Termination()
 {
     // Release the dependency.
     SqlDependency.Stop(connectionString, queueName);
 }