**Possible References**

I have found a similar problem: [Refreshing a SQL database connection](https://stackoverflow.com/questions/648450/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](https://stackoverflow.com/questions/2664910/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?