1

I was caching the results inside a DataSet using the SqlCacheDependency .

Called out a simple code in page load

string conn= WebConfigurationManager.ConnectionStrings["NorthwindEntities"].ConnectionString; 
SqlConnection con = new SqlConnection(conn); 
string query = "SELECT EmployeeID, FirstName, LastName, City FROM dbo.Employees"; 
SqlCommand cmd = new SqlCommand(query, con); 
SqlDataAdapter dadapter= new SqlDataAdapter(cmd);

DataSet usage :

DataSet ds = new DataSet(); 
dadapter.Fill(ds, "Employees"); 

And cached it as :

SqlCacheDependency empDependency = new SqlCacheDependency(cmd); 
Cache.Insert("Employees", ds, empDependency, DateTime.Now.AddMinutes(10),Cache.NoSlidingExpiration);

However, I run the page, data loads in grid view and then I modify manually from SQLServer itself. I reload the page and the changed data is immediately visible.

Which line is creating issue OR is anything missing ?

1 Answer 1

1

Got the issue here.

SqlDependency notification system wasn't up and running. This was resolved by correctly setting up the Global.asax file Application_Start method.

protected void Application_Start()
 {
    string connString =   
    ConfigurationManager.ConnectionStrings["ProductionSystem"].ConnectionString;
    SqlDependency.Start(connString); // starting the listener service 
}

This link helped me.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.