none
New DataContext returns stale data RRS feed

  • Question

  • After a serious session of code cleanup, I noted that one DB get operation I'm running against a DataContext seems to have changed behavior.

    I have a client app, plugging data over WCF where the WCF server part extracts data from an SQL DB using Linq2SQL. When I update certain data properties on the client, I see the data being changed in the database as usual (confirmed by querying the database manually using management studio). However, if I have the client pull the data again, the data being returned to the client is the state before the update. I have this happening to three tables - regardless of whether I access that data via the built-in FK handling or simply querying the object by its PK.

    I'm using a separate data context for data extraction and for updating.

    Restarting the client won't do anything, and I know WCF isn't the problem because the data being extracted from the DB is already stale (confirmed by stepping through the extraction code in the DB layer). If I restart the server part, then I get the data as it is in the DB, but after the first get, the server will continue returning that data that was initially extracted, regardless of any update operations that happen thereafter.

    So I'm wondering, is there a caching mechanism I'm unaware off, and how can I turn this behavior off for the affected table?

    @edit: I noted that at least for one of the affected table, I access the same record twice - once by first creating a separate data context then extracting the data, and another one as part of an extended query (data extraction then follows in the same context.. so there's a linq2sql query, then a lot more linq queries on the returned objects).

    Monday, April 2, 2012 8:38 AM

Answers

  • Ahh - got it. Finally having found the proper search term (stale data) the first or second search result in this forum pointed to an issue where somebody had a global data context, and sure enough, the DB layer had one that was being used in a few specific instances - just the cases that were giving me trouble. Opening a new context for those data extractions yielded the desired behavior.
    Monday, April 2, 2012 5:11 PM

All replies

  • Ahh - got it. Finally having found the proper search term (stale data) the first or second search result in this forum pointed to an issue where somebody had a global data context, and sure enough, the DB layer had one that was being used in a few specific instances - just the cases that were giving me trouble. Opening a new context for those data extractions yielded the desired behavior.
    Monday, April 2, 2012 5:11 PM
  • Hi Stephan,

    Thanks for sharing your experience here.

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, April 3, 2012 1:16 AM
    Moderator