Running out of connections in pool

99封情书 提交于 2019-12-04 16:55:50

From my comment, I'll convert to an answer.

It looks like you are trying to close your Connection objects before the Command objects, and since the Command objects reference a connection, it might be keeping the connection alive.

Try switching them around:

//Clean Up Command Object
if (mobj_SqlCommand != null)
{
  mobj_SqlCommand.Dispose();
}

if (mobj_SqlConnection != null)
{
  if (mobj_SqlConnection.State != ConnectionState.Closed)
  {
    mobj_SqlConnection.Close();
  }
  mobj_SqlConnection.Dispose();
}

If I remember correctly, SqlHelper dispose does not automatically close the connection. You need to explicitly close it.

We always wrap our usage of SqlHelper in a try/finally and explicitly call close in the finally.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!