- //Here we will add a function for register notification (will add sql dependency)
- public void RegisterNotification(DateTime currentTime)
- {
- string conStr = ConfigurationManager.ConnectionStrings["sqlConString"].ConnectionString;
- string sqlCommand = @"SELECT [ContactID],[ContactName],[ContactNo] from [dbo].[Contacts] where [AddedOn] > @AddedOn";
- //you can notice here I have added table name like this [dbo].[Contacts] with [dbo], its mendatory when you use Sql Dependency
- using (SqlConnection con = new SqlConnection(conStr))
- {
- SqlCommand cmd = new SqlCommand(sqlCommand, con);
- cmd.Parameters.AddWithValue("@AddedOn", currentTime);
- if (con.State != System.Data.ConnectionState.Open)
- {
- con.Open();
- }
- cmd.Notification = null;
- SqlDependency sqlDep = new SqlDependency(cmd);
- sqlDep.OnChange += sqlDep_OnChange;
- //we must have to execute the command here
- using (SqlDataReader reader = cmd.ExecuteReader())
- {
- // nothing need to add here now
- }
- }
Loading
Madan ShekarPosted Oct 26, 2018, 7:09 AM
Laxmidhar SahooPosted Oct 26, 2018, 2:49 AM
Gaurav RajPosted Oct 25, 2018, 2:29 AM
hello
Kalyani ShevalePosted Oct 25, 2018, 1:28 AM