Hi< xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
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
{
public partial class Form1 : Form
{
private int ChangeCount = 0;
private DataSet dataSet = new DataSet();
private delegate void UICallback();
public Form1()
{
InitializeComponent();
}
private void btnGetData_Click(object sender, EventArgs e)
{
GetData();
this.ChangeCount = 0;
}
private void GetData()
{
this.dataSet.Clear();
string strConnection = @"Data Source=server\SQL2005;Integrated Security=True;Initial Catalog=FraasDB";
SqlConnection SQLConnection = new SqlConnection(strConnection);
string SQL = "SELECT * FROM Table_1";
SqlDataAdapter SQLDataAdapter = new SqlDataAdapter(SQL, SQLConnection);
SqlDependency SQLDependency = new SqlDependency(SQLDataAdapter.SelectCommand);
SQLDependency.OnChange += new OnChangeEventHandler(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(new UICallback(ReBind));
MessageBox.Show(e.Info.ToString());
}
private void 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

Event (OnChange) of (SqlDependency) object occur like the timers , not only on the change appear in the database
andre_eads
The SQL Statement Must be
SELECT F1, F2 FROM dbo.Table_1
Now it's work fine
thanks
Steven13174206
I have change the SQL Statement but still I get The Seme result
SELECT t.F1, t.F2 FROM Table_1 t
With my regarding
Fraas
satishchebbi
Select t.col1, t.col2, t.col3 from Table_1 t
On tell-tale sign that the statement is wrong is that the callback happens immediately after the command hes been executed.
For more info, you can read some stuff I wrote on my blog a while back.
Hope this helps!
Niels