之前没有发生这种情况,所以我假设我所做的事情导致了这一点,但我看不出它会是什么。
我已经针对sql server 2005数据库设置了linq2sql。我只使用存储过程。
我的大多数程序都运行正常,但是这个特定的更新过程有时会连续几次被触发(克隆标题记录的详细信息)。
这会导致超时,并且运行脚本以查看打开的连接会显示我的应用连接都处于休眠状态并占用空间。
有什么想法,建议吗?
我的datacontext被设置为服务类中的静态变量:
private static WarehouseSystemDataContext dc
{
get
{
// It is being passed a closed SqlConnection object
WarehouseSystemDataContext _dc =
new WarehouseSystemDataContext(Constants.getWarehouseSystemConn());
_dc.ObjectTrackingEnabled = false;
_dc.CommandTimeout = 600;
return _dc;
}
}
答案 0 :(得分:3)
每次引用datacontext时都在创建新连接
private static WarehouseSystemDataContext _dc
private static WarehouseSystemDataContext dc
{
get
{
if(_dc == null)
{
// It is being passed a closed SqlConnection object
_dc = new WarehouseSystemDataContext(Constants.getWarehouseSystemConn());
_dc.ObjectTrackingEnabled = false;
_dc.CommandTimeout = 600;
}
return _dc;
}
}