public void RegisterNotification(DateTime currentTime) { string SqlConnectionString; using (var context = new AMotorsEntities()) SqlConnectionString = context.Database.Connection.ConnectionString; string sqlCommand = @"Select [product_Id], [productCategory_Id],[name] ,[model_Id] ,[SpecialPrice] ,[OldPrice] ,[Price] ,[StockQuantity] ,[FullDescription] ,[ShortDescription] ,[OEM_num] ,[ST_num] ,[Part_num] FROM[AMotors].[dbo].[product]"; using (SqlConnection sqlCon = new SqlConnection(SqlConnectionString)) { SqlCommand cmd = new SqlCommand(sqlCommand, sqlCon); if (sqlCon.State != System.Data.ConnectionState.Open) { sqlCon.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 //} } }
protected void Application_Start(object sender, EventArgs e) { using (var context = new AMotorsEntities()) SqlConnectionString = context.Database.Connection.ConnectionString; // Code that runs on application startup AreaRegistration.RegisterAllAreas(); GlobalConfiguration.Configure(WebApiConfig.Register); RouteConfig.RegisterRoutes(RouteTable.Routes); //if (!string.IsNullOrEmpty(SqlConnectionString)) //SqlDependency.Start(SqlConnectionString); }