Event (OnChange) of (SqlDependency) object occur like the timers , not only on the change ap
Hi
I have Use this Code snippet to apply the concept of notification in SQL Server 2005 Developer Edition April CTP and Also I use VS.NET 2005 Beta2
But the problem the Event (OnChange) of (SqlDependency) object occur like the timers hundreds time not only on the change appear in the database … Why ? and How can stop this event to occur only when the change in the database ?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WindowsApplication1
{
publicpartialclassForm1 :Form
{
privateint ChangeCount = 0;
privateDataSet dataSet =newDataSet();
privatedelegatevoidUICallback();
public Form1()
{
InitializeComponent();
}
privatevoid btnGetData_Click(object sender,EventArgs e)
{
GetData();
this.ChangeCount = 0;
}
privatevoid GetData()
{
this.dataSet.Clear();
string strConnection =@"Data Source=server\SQL2005;Integrated Security=True;Initial Catalog=FraasDB";
SqlConnection SQLConnection =newSqlConnection(strConnection);
string SQL ="SELECT * FROM Table_1";
SqlDataAdapter SQLDataAdapter =newSqlDataAdapter(SQL, SQLConnection);
SqlDependency SQLDependency =newSqlDependency(SQLDataAdapter.SelectCommand);
SQLDependency.OnChange +=newOnChangeEventHandler(this.SQLDependency_OnChange);
SQLDataAdapter.Fill(dataSet,"Table1");
this.dataGridView1.DataSource = dataSet;
this.dataGridView1.DataMember ="Table1";
}
void SQLDependency_OnChange(object sender,SqlNotificationEventArgs e)
{
this.ChangeCount++;
this.Invoke(newUICallback(ReBind));
MessageBox.Show(e.Info.ToString());
}
privatevoid ReBind()
{
GetData();
this.toolStripStatusLabel1.Text =this.ChangeCount.ToString();
}
}
}
And also when I try to get information about the changes type with the help of this line of code Invalid value
void SQLDependency_OnChange(object sender,SqlNotificationEventArgs e)
{
MessageBox.Show(e.Info.ToString());
}
And thanks with my best regarding

