Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There seem to be some problems with the MySQL .NET library. A few days ago they fixed some of those issues with 6.2.2 related to releasing connections. But there is also a problem with SubSonic. I used the LINQ templates with MySQL to generate my classes. Whenever FirstOrDefault() or First() (the other similar functions probably have the same issue).</p> <p>For a query such as:</p> <pre><code>var db = new MyDb("CONNECTIONSTRING_NAME"); var userExt = (from pe in db.PhoneExtensions where pe.FirstName.ToLower() == firstName.ToLower() &amp;&amp; pe.LastName.ToLower() == lastName.ToLower() select pe.Extension).FirstOrDefault(); </code></pre> <p>This will cause the query to be executed and the reader will <strong>not</strong> be disposed.</p> <p>The problem is in Linq.Structure.DbQueryProvider in the Project of T method.</p> <pre><code>while (reader.Read()) { yield return fnProjector(reader); } reader.Dispose(); </code></pre> <p>The Dispose() never gets called when using FirstOrDefault() and other similar methods.</p> <p>A Simple fix:</p> <pre><code>try { while (reader.Read()) { yield return fnProjector(reader); } } finally { reader.Dispose(); } </code></pre> <p>Simple quick test showing the issue:</p> <pre><code>private class DbDataReader : System.IDisposable { #region IDisposable Members public void Dispose() { } #endregion } private class DbQueryProvider { private DbDataReader _reader; public bool IsReaderDisposed { get { return _reader == null; } } public DbQueryProvider() { _reader = new DbDataReader(); } public IEnumerable&lt;int&gt; Project(int numResults) { int i = 0; while (i &lt; numResults) { yield return i++; } _reader.Dispose(); _reader = null; } public IEnumerable&lt;int&gt; ProjectWithFinally(int numResults) { int i = 0; try { while (i &lt; numResults) { yield return i++; } } finally { _reader.Dispose(); _reader = null; } } } [Test] public void YieldReturn_Returns_TrueForIsReaderDisposed() { const int numResults = 1; var qp1 = new DbQueryProvider(); var q1 = qp1.Project(numResults); Assert.IsInstanceOf(typeof(int), q1.First()); var qp2 = new DbQueryProvider(); var q2 = qp2.Project(numResults); Assert.IsInstanceOf(typeof(int), q2.FirstOrDefault()); var qp3 = new DbQueryProvider(); var q3 = qp3.Project(numResults); Assert.IsInstanceOf(typeof(int), q3.Single()); var qp4 = new DbQueryProvider(); var q4 = qp4.Project(numResults); Assert.IsInstanceOf(typeof(int), q4.SingleOrDefault()); Assert.IsTrue(qp1.IsReaderDisposed); Assert.IsTrue(qp2.IsReaderDisposed); Assert.IsTrue(qp3.IsReaderDisposed); Assert.IsTrue(qp4.IsReaderDisposed); } [Test] public void YieldReturnFinally_Returns_TrueForIsReaderDisposed() { const int numResults = 1; var qp1 = new DbQueryProvider(); var q1 = qp1.ProjectWithFinally(numResults); Assert.IsInstanceOf(typeof(int), q1.First()); var qp2 = new DbQueryProvider(); var q2 = qp2.ProjectWithFinally(numResults); Assert.IsInstanceOf(typeof(int), q2.FirstOrDefault()); var qp3 = new DbQueryProvider(); var q3 = qp3.ProjectWithFinally(numResults); Assert.IsInstanceOf(typeof(int), q3.Single()); var qp4 = new DbQueryProvider(); var q4 = qp4.ProjectWithFinally(numResults); Assert.IsInstanceOf(typeof(int), q4.SingleOrDefault()); Assert.IsTrue(qp1.IsReaderDisposed); Assert.IsTrue(qp2.IsReaderDisposed); Assert.IsTrue(qp3.IsReaderDisposed); Assert.IsTrue(qp4.IsReaderDisposed); } </code></pre> <p>YieldReturnFinally_Returns_TrueForIsReaderDisposed passes but YieldReturn_Returns_TrueForIsReaderDisposed fails.</p> <p>I have tested this on the project I am working on which will soon be in production and this seems to work without any problems. Tested with a connection pool max size of 5 and had no connection pool issues (never ran out of connections on my dev machine when doing 1 query at a time). I also found some issues in Extensions.Database related to type changing and assignments.</p> <p>I forked the project on github, committed my changes and did a pull request, hopefully that gets to the right people.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload