string cs = "Server=vcgmo;Initial Catalog=AdventureWorks; User Id=sa; password=xxxxxx;";
SqlConnection cn;
SqlDependency.Start(cs);
cn = new SqlConnection(cs);
cn.Open();
SqlDataReader r;
SqlCommand cmd;
SqlDependency sd;
SqlDataAdapter ad;
cmd = new SqlCommand("[dbo].[uspTest]", cn);
sd = new SqlDependency(cmd);
sd.OnChange += new OnChangeEventHandler(sd_OnChange);
r = cmd.ExecuteReader();
SqlDependency.Stop(cs);
void sd_OnChange(object sender, SqlNotificationEventArgs e) { }
Note: To enable SQL Notification, must run
ALTER DATABASE [DatabaeName] SET ENABLE_BROKER;
in the Database
Wednesday, November 12, 2008
Sql Query Notification setup code
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment