0

I'm working with MSSQL Server 2008 and made a database in it. Now i made a ASP.Net (MVC 4) project and connected it to the database. I let visual studio generate the Entity Data Model and everything is working fine so far. Now i have a table for a many to many relation with ofcourse a PK, and two FK. When i manualy insert a row to the database with Microsoft SQL Server Management Studio and i refresh my web page this new row doesn't show up.

I'm 100% sure there is nothing wrong with the C# code (ASP.Net) but after X minutes the row show up :s.

Do i need to update the datasource somewhere or what do i do wrong? (it's my first ASP.Net project :))

Thnx!

Code edit:

private dbEntities db = new dbEntities();

This dbEntities is generated by visual studio from the SQL Server and contains models for all tables.

Stefan Koenen
  • 2,167
  • 2
  • 17
  • 31

1 Answers1

1

It sounds like your data context is stale (it's retrieving the data from memory and not going to the DB).

See this question or this one for a possible solution.

Edit: Looking at your sample code, I'm going to guess that this has been declared as a page (or class) member. You should wrap this in a using statement so the object context can be disposed:

e.g.

using (var db = new dbEntities())
{
    //perform work
}
Community
  • 1
  • 1
Damon
  • 2,987
  • 7
  • 21
  • 28
  • Hey, first of all thnx for your answer, but i'm not sure this is the solution. I can't find any object i can call the 'refresh' on. – Stefan Koenen Sep 11 '13 at 09:56
  • How are you retrieving your data? If you're using EF then you must be using a data context somewhere to query your data. You need to call refresh on this object. Perhaps paste your data access code in your question. – Damon Sep 11 '13 at 10:01
  • Might need a little bit more...don't you see a refresh method on db? I think that is your dbcontext. – Damon Sep 11 '13 at 10:13
  • that db is generated by visual studio (ADO.Net entity data model), i also though i can refresh this, but can't find anything. – Stefan Koenen Sep 11 '13 at 10:19
  • Just seen that if you're using dbcontext (ef 4.1 +) you need to cast it to objectcontext to get at the refresh method http://stackoverflow.com/questions/13177718/dbcontext-does-not-contain-a-definition-for-refresh – Damon Sep 11 '13 at 10:20
  • The only problem was that i need to make a new object for the db. It works without the refresh :). Thnx! – Stefan Koenen Sep 11 '13 at 10:39