Skip to content

Close() or Dispose() throws if Close() has already been called #620

Closed
@Timovzl

Description

@Timovzl

When the data reader is disposed or closed after it has already been closed, it throws. This is undesirable and sometimes even problematic.

A disposable object should always (generally) be disposed. If one part of the process deems it correct to close the reader, but disposing it is not its responsibility, then another part of the process must be able to dispose it.

The above appears in particular when ExecuteReader(CommandBehavior.CloseConnection) is used, where disposing the reader closes the connection. The connection should still be disposed, but particularly if a class receives a reader through its constructor (as is my case), it cannot know if that reader will close its connection, so it has to dispose it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions