There is already an open DataReader associated with this Connection which must be closed first
2017-09-18 19:11
741 查看
最近在写WebApi接口,遇到一些问题,总结一下。这些问题未必跟WebApi有关系,比较琐碎。
总结列表:
1. There is already an open DataReader associated with this Connection which must be closed first
2. npm install 失败
3. WebApi HTTP Put 405 Method not allowed
问题现象:一个接口被多次调用,可以认为是多线程调用接口,接口内部使用了C#的Async Await,代码形如:
return new GetXResponse
{
A= await A.GetAAsync(xx),
B= await B.GetBAsync(xx),
C= await C.GetCAsync(xx),
D= await D.GetDAsync(xx),
E= await E.GetEAsync(xx),
F= await F.GetFAsync(xx),
G= await G.GetGAsync(xx)
};
犯了一个错误,A、B、C、D等等都会连接数据库,连接数据库的代码,使用using不当
using (Connection)
{
return (await conn.QueryAsync<T>(sql, parms)).ToList();
}
Connection是在构造函数完成的初始化 new MySqlConnection,多线程调用时,using未及时回收数据库连接,修改如下之后,该异常可修复。
using (var conn = new MySqlConnection(ConnString))
{
return (await conn.QueryAsync<T>(sql, parms)).ToList();
}
相关文章推荐
- There is already an open DataReader associated with this Connection which must be closed first
- There is already an open DataReader associated with this Connection which must be closed first
- There is already an open DataReader associated with this Connection which must be closed first
- There is already an open DataReader associated with this Connection which must be closed first
- There is already an open DataReader associated with this Connection which must be closed first
- C#数据库操作错误:There is already an open DataReader associated with this Connection which must be closed..
- 解决"There is already an open DataReader associated with this Command which must be closed first." exception in EF 中
- 关于MultipleActiveResultSets属性导致的There is already an open DataReader associated with this Command which must be closed first的解决方法
- There is already an open DataReader associated with this Command which must be closed first." exception in Entity Framework
- LINQ: There is already an open DataReader associated with this Command which must be closed first
- MySql: There is already an open DataReader associated with this Command which must be closed first.2/16
- error 'there is already an open datareader associated with this command which must be closed first'
- LINQ: There is already an open DataReader associated with this Command which must be closed first
- LINQ链接数据库出错(There is already an open DataReader associated with this Command which must be closed first )
- LINQ: There is already an open DataReader associated with this Command which must be closed first
- EF "There is already an open DataReader associated with this Command which must be closed first."
- There is already an open DataReader associated with this Command which must be closed first
- 多线程下,多次操作数据库报错,There is already an open DataReader associated with this Command which must be closed first.
- There is already an open DataReader associated with this Command which must be closed first的错误解决办法
- "There is already an open DataReader associated with this Command which must be closed first"错误