Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6954139
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:34:02+00:00 2026-05-27T14:34:02+00:00

Possible References I have found a similar problem: Refreshing a SQL database connection which

  • 0

Possible References

I have found a similar problem: Refreshing a SQL database connection which does not suggest a solution (more to check the code)

and LINQ to SQL does not update when data has changed in database which should be closer to my problem.

Setup

I allow the user to change the connectionstring at runtime (through SqlConnectionStringBuilder, EntityConnectionStringBuilder and “New EntityClient.EntityConnection(entityconn())”)
I use the EntityConnection with .Open and with “New Database.DatabaseContainer(entityConnection)”

I keep using the same container for reading db data. and for calling “.SaveChanges” and do not explicit use transactions so far. (I expected “SaveChanges” to automatically do a commit and throw exceptions if the cached data has changed before committing)

Problem Description

When I execute 2 programs and change data with one program, then the other does not notice the changes when it established the connection before the other program committed.

For example if I have 2 times the same program (A and B), the following happens:
Start A, Start B, Change data in A, B is unable to read the changed data (because it started the connection before A finished the changes).

Question

How to refresh the local cached data, and how to deal with racing problems?

When I refresh connection for A and then change the data, but meanwhile B was refreshed and also starts to change data, then B may overwrite the changes from A without noticing. This happens whenever the database is changed after a refresh. The second question I linked above seems not to deal with that problem.

My guessed ideas how I may be able to solve the problem

Maybe the command “Container.Refresh(Objects.RefreshMode.StoreWins, entity) may help with that, but I am not sure what object to give as entity. the outdated one that I just read from the cached database? And tere is still the problem, that I am not sure when that conflict will occur.

Maybe it should be somethign with transaction or changing transactionscope, assuring that all changes are only made (or repeatedly tried to make) until there were no changed in the database since the transaction started? Is that possible or how to deal with data that was already changed by another program with active transaction?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T14:34:02+00:00Added an answer on May 27, 2026 at 2:34 pm

    What you see is identity map behavior and it is core feature of EF.

    To solve problems with refreshing you can either use

    Refresh

    objectContext.Refresh(RefreshMode.StoreWins, entity); 
    

    entity is object previously retrieved from the database which you want that you want to refresh.

    MergeOption

    objectContext.YourEntitySet.MergeOption = MergeOption.OverwriteChanges;
    var data = objectContext.YourEntitySet.
                  /* Any query you want to execute to refresh your data */
                  ToList();
    

    MergeOption controls the way how data are read to identity map. Default settings is AppendOnly which will materialize only entities which were not previously loaded but entities already loaded will remain intact – that is the core feature because otherwise any query would be able to overwrite your unsaved state.

    The second question is completely unrelated to your initial problem. If you are afraid that one application can change data during preparing modifications in other application you need to deal with concurrency.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know it is not recommended, but is it possible? The only references I
I keep getting errors using Sql Compact. I have seen that it is possible
I have an asp.net mvc 2 application with a SQL Server database accessed by
Possible Duplicate: Learning jQuery and Getting Better at Javascript I have found jQuery very
I have an ASP Classic application which references some VB6 COM OBJECTS. One of
Is it possible to share references to C# objects between C# and C++ code
In Visual Studio 2005-2015 it is possible to find all lines containing certain references
Is it possible to reference a .NET Assembly from a SQL Server Stored procedure
I have two questions. 1) I found a little gem of code for how
Possible Duplicate: Is it possible to pass parameters by reference using call_user_func_array()? I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.