我正在使用以下代码访问本地 sql express 数据库:
using (MessageBoxDbDataContext db = new MessageBoxDbDataContext())
{
var msg = (from msgs in db.messages
where id == msgs.id select msgs).FirstOrDefault();
if (msg == null)
{
throw new Exception(
string.Format("Message with id {0} was not found in db.", id));
}
msg.status = (int)status;
msg.updated_at = DateTime.Now;
db.SubmitChanges();
}
有时我会在以下位置收到“将指定的计数添加到信号量会导致它超过其最大计数”错误:
var msg = (from msgs in db.messages
where id == msgs.id select msgs).FirstOrDefault();
如果有人有想法,我正试图弄清楚为什么会发生这种情况。