MySQL实时更新异常
我构建了一个 C# 应用程序,每 10 毫秒更新一次 MySQL 数据库表。该应用程序为每次更新创建一个单独的线程。使用 Workbench,我可以看到有很多连接,并且在一段时间内,这已经相当成功。但最近,我发现在成功执行 2-3 小时后,我收到一个异常,显示“未找到表 xxxx”。我使用实体框架进行了读取和更新,如下
try
{
u5s = (from u in cxt.universe5s
where u.CATEGORY == tval
select u).ToList();
. . .
u5.PC_CHANGE = chval;
cxt.SaveChanges();
}
catch (Exception myEx)
{
//throws my 'table not found' exception here
}
使用 NET 4.0 和 MySql 5.5.9。还有其他人有这样的经历吗?会不会是连接数不足导致的?在这种情况下,保存更改后关闭连接的最佳实践是什么?
真挚地 理查德
I've built a C# application that updates a MySQL db table every 10 ms. The app creates a separate thread for each update. Using Workbench, I can see that there are many connections and for a while, this has been quite successful. Recently though, I find that after 2-3 hours of successful execution I am getting an exception which says "Table xxxx not found". I have both a read and an update using Entity Framework, as follows
try
{
u5s = (from u in cxt.universe5s
where u.CATEGORY == tval
select u).ToList();
. . .
u5.PC_CHANGE = chval;
cxt.SaveChanges();
}
catch (Exception myEx)
{
//throws my 'table not found' exception here
}
Using NET 4.0 and MySql 5.5.9. Does anyone else have an experience like this? Could it be caused by running out of connections? What is the best practice in this case as far as closing the connection after saving changes?
Sincerely
Richard
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这听起来像是一个并发问题。您可能会尝试锁定单个连接对象。这也将减轻服务器的压力。
请参阅 http://msdn.microsoft.com/ en-us/library/c5kehkcz%28v=vs.80%29.aspx 了解详细信息。
希望这有帮助。
This sounds like a concurrency issue. You might try to lock on a single connection object. That would also reduce the stress on the server.
See http://msdn.microsoft.com/en-us/library/c5kehkcz%28v=vs.80%29.aspx for details.
Hope this helps.