简体   繁体   English

使用LINQ to SQL用尽数据库连接

[英]Running out of DB connections using LINQ to SQL

In developing a relatively simple web service, that takes the data provided by a post and records it in a database table, we're getting this error: 在开发一个相对简单的Web服务时,该服务采用了帖子提供的数据并将其记录在数据库表中,因此出现了以下错误:

Exception caught: The remote server returned an error: (500) Internal Server Er or. 捕获到异常:远程服务器返回错误:(500)Internal Server Er or。 Stack trace: at System.Net.HttpWebRequest.GetResponse() 堆栈跟踪:位于System.Net.HttpWebRequest.GetResponse()

on some servers, but no others. 在某些服务器上,但在其他服务器上没有。 The ones that are getting this are the physical machines, the others are virtual, and obviously the physical servers are far more powerful. 获得此功能的是物理机,其他是虚拟机,显然物理服务器的功能要强大得多。

As far as we can tell, the problem is that the DB connections aren't being released back to the pools after each query. 据我们所知,问题在于在每次查询后数据库连接都没有释放回池中。 I'm using the using pattern below: 我正在使用以下使用模式:

                using (VoteDaoDataContext dao = new VoteDaoDataContext())
                {

                    dao.insert_response_and_update_count(answerVal, swid, agent, geo, DateTime.Now, ip);
                    dao.SubmitChanges();
                    msg += "Thank you for your vote.";
                    dao.Dispose();
                }

I added the dao.Dispose() call to ensure that connections are released when the method finishes, but I don't know whether or not it's necessary. 我添加了dao.Dispose()调用以确保在方法完成时释放连接,但是我不知道是否有必要。

Am I using this pattern correctly? 我是否正确使用此模式? Is there something else I need to do to ensure that connections get returned to the pools correctly? 我还需要做其他事情来确保连接正确返回到池中吗?

Thanks! 谢谢!

Your diagnostic information is not good enough. 您的诊断信息不够好。 An HTTP/500 isn't enough detail to really tell if your theory is correct. HTTP / 500的详细信息不足以真正说明您的理论是否正确。 You're going to need to capture a full stack trace in your logging if you want to get to the problem. 如果要解决此问题,您将需要在日志记录中捕获完整的堆栈跟踪。 I think you've jumped to a conclusion here. 我想您已经在这里得出结论了。 And no, you do not need that Dispose() before the end of your using{} block. 不,在using {}块结束之前,不需要Dispose()。 That's what using{} does . 那就是using {} 所做的

I thought that dispose() call was redundant, but I wanted to be sure. 我以为dispose()调用是多余的,但我想确定一下。

We're seeing the connection pools saturating in the SQL logs (I can't look at the directly, I'm just a developer, and this stuff's running in a prod environment), and my ops guy said he's seeing connections timing out... and once they time out, the server starts running again, until the next time it saturates the connection pool. 我们看到SQL日志中的连接池已饱和(我不能直接看,我只是一名开发人员,并且这些东西都在产品环境中运行),我的操作人员说他正在看到连接超时。 ..并且一旦超时,服务器将再次运行,直到下次饱和连接池为止。

We're going through the process of tweaking the connection pool settings at the moment... I wanted to be certain that I wasn't doing anything wrong, since this is my first time using Linq. 目前,我们正在调整连接池设置的过程中...我想确定自己没有做错任何事情,因为这是我第一次使用Linq。

Thanks! 谢谢!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM