使用 linq/entity、MVC2 时出现奇怪的超时

发布于 2024-11-28 18:18:03 字数 481 浏览 0 评论 0原文

我刚刚随机开始遇到这个问题,之前一直到今晚都很好。我不想碰超时的东西,我相信这是没有必要的。

这是一个简单的查询。

{"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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

将军与妓 2024-12-05 18:18:03

你可以避免这种排序:

var post = 
    from p in con.blog_posts
    where p.post_dt == con.blog_posts.Max(post=>post.post_dt) 
    select p

you could avoid the sort:

var post = 
    from p in con.blog_posts
    where p.post_dt == con.blog_posts.Max(post=>post.post_dt) 
    select p
蝶舞 2024-12-05 18:18:03

其他数据库查询是否按预期工作?转到您的数据库并运行该查询,看看返回需要多长时间。尝试运行精确的查询(在 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文