使用 linq/entity、MVC2 时出现奇怪的超时
我刚刚随机开始遇到这个问题,之前一直到今晚都很好。我不想碰超时的东西,我相信这是没有必要的。
这是一个简单的查询。
{"Timeout expired. The timeout period elapsed prior to completion of the
operation or the server is not responding."}
这是导致超时的代码。
var post = (from p in con.blog_posts
orderby p.post_dt descending
select p).First();
任何人都可以想到我应该检查以尝试解决此问题的任何缝隙吗?
编辑:我可以使用 Management Studio 连接到服务器,它已经启动了..
I've just randomly started getting this issue, and previously it has been fine up until tonight. I do not want to touch the timeout stuff, I believe it's not needed.
It's a simple query.
{"Timeout expired. The timeout period elapsed prior to completion of the
operation or the server is not responding."}
Here is the code causing the timeout..
var post = (from p in con.blog_posts
orderby p.post_dt descending
select p).First();
Can anyone think of any crevices I should check to try an resolve this?
edit: I can connect to the server with management studio and it is up..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你可以避免这种排序:
you could avoid the sort:
其他数据库查询是否按预期工作?转到您的数据库并运行该查询,看看返回需要多长时间。尝试运行精确的查询(在 SQL Profiler 中捕获它)。这将告诉您数据库是否只是对该查询执行缓慢,或者是否是另一个问题。
我的第一个猜测是您在
post_dt
列上没有索引。直接在 SQL 中尝试查询将证明或反驳这一点。如果查询需要很长时间才能运行,请在该列上添加非聚集索引并重试。Are other database queries working as expected? Go to your database and run that query and see how long it takes to return. Try to run the exact query (capture it in SQL Profiler). This will tell you if your database is simply performing slowly for this query, or whether it's another issue.
My first guess would be that you don't have an index on the
post_dt
column. Trying the query directly in SQL will prove or disprove this. If the query takes a long time to run, add a nonclustered index on that column and retry.