Skip to content

DataReader remains open in some cases #71

@AlexUstinov

Description

@AlexUstinov

The code below demonstrates the issue with the data reader. It looks like in some cases underlying SQL data reader remains open after enumeration blocking attempts to commit a transaction.
The code below demonstrates the issue.

  // The model
  [HierarchyRoot]
  [KeyGenerator(KeyGeneratorKind.None)]
  public class Item: Entity
  {
    [Field, Key]
    public Guid Id { get; private set; }

    public Item(Session session, Guid id)
      : base(session, id)
    { }
  }

  // The failing code
  // NOTE: There are no Item records in the table
  using (var session = Domain.OpenSession()) {
    using (var tx = session.OpenTransaction()) {
      var list = new List<Guid>();
      var sequence = Enumerable.Empty<Guid>().Union(session.Query.All<Item>()
        .Where(item => item.Id == Guid.Empty)
        .Select(item => item.Id));
      foreach (var guid in sequence) {
        list.Add(guid);
      }

      Assert.AreEqual(0, list.Count);
      tx.Complete();
    }
  }

When executed, this code throws an exception on the attempt to complete the transaction using block.

Xtensive.Orm.StorageException : SQL error occured.
SQL error details 'Type: Unknown;'
Original message 'The transaction operation cannot be performed because there are pending requests working on this transaction.'
  ----> System.Data.SqlClient.SqlException : The transaction operation cannot be performed because there are pending requests working on this transaction.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions