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.

1 Answer 1

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
}
Sign up to request clarification or add additional context in comments.

6 Comments

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.
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.
Might need a little bit more...don't you see a refresh method on db? I think that is your dbcontext.
that db is generated by visual studio (ADO.Net entity data model), i also though i can refresh this, but can't find anything.
Just seen that if you're using dbcontext (ef 4.1 +) you need to cast it to objectcontext to get at the refresh method stackoverflow.com/questions/13177718/…
|

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.