SubSonic:MySqlDataReader 关闭连接
执行事务时遇到问题
我正在使用 SubSonic 2.1,并在使用SharedDbConnectionScope 和 TransactionScope 。 问题是,在 obj.Save() 方法中,我得到一个“连接必须有效且打开”的异常,
我将问题跟踪到这一行:
// Loads a SubSonic ActiveRecord object
User user = new User(User.Columns.Username, "John Doe");
在 User 类的这个构造函数中,调用了一个方法“LoadParam”,该方法最终看起来
if (rdr != null)
rdr.Close();
rdr.Close() 隐式关闭了我的连接,这在使用 AutomaticConnection 时很好。但在事务期间,关闭连接通常不是一个好主意:-)
我的问题是这是设计使然还是 MySqlDataReader 中的错误。
I am using SubSonic 2.1 and entcountered a problem while executing a Transaction with
SharedDbConnectionScope and TransactionScope.
The problem is that in the obj.Save() method I get an "The connection must be valid and open" exception
I tracked down the problem to this line:
// Loads a SubSonic ActiveRecord object
User user = new User(User.Columns.Username, "John Doe");
in this Constructor of the User class a method "LoadParam" is called which eventually does
if (rdr != null)
rdr.Close();
It looks like the rdr.Close() implicitly closes my connection which is fine when using the AutomaticConnection. But during a transaction it is usally not a good idea to close the connection :-)
My Question is if this is by design or if it's an error in the MySqlDataReader.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这很棘手!
经过一番调试后,我在 SubSonic2 MySqlDataReader.cs 文件中发现了以下方法:
这是错误的,因为我使用的是 SharedDbConnection。在 SqlDataProvider 中它已经被修复,但对于 MySqlDataReader 还没有修复。
它应该看起来像这样:
相当严重的错误,它使得事务中的查询变得不可能(我必须承认我以前从未需要过这个)。
That was tricky!
After a bit debugging I found the following method in the SubSonic2 MySqlDataReader.cs file:
Which is wrong since I am using a SharedDbConnection. In the SqlDataProvider it has been fixed already but not for MySqlDataReader.
It should look like this:
Pretty heavy bug, it rendered Querying in a Transaction impossible (I must admit I never needed this before).