I came across a very strange problem which never happened to me before.
In the login code:
var sqlLogin = db.LoginRetrieve(loginID, archived).SingleOrDefault();
//(db is the linq data context)
--problem:
If two users login 开发者_开发问答at the same time, this line of code will throw an exception which is "The required column 'UserLoginID' does not exist in the results." But if a single user logs in or two users don't click the button at the same time, it will have no exception.
Is there anyone can share some lights on this? Thanks in advance.
Han
I suspect that your DataContext is shared between requests.
Don't do that.
You should create a separate DataContext for each request.
Otherwise, you'll get nasty threading issues like this one. (DataContext isn't thread-safe)
In general, you should be very careful when sharing objects between requests (eg, static
s or Application / Session state).
Unless you know specifically otherwise, you should assume that the object is not thread-safe and cannot be shared.
精彩评论