1

Does the following code, cleanup all SqlDataReaders correctly:

using (IDataReader reader = SqlHelper.GetDataReader(sql.ToString())) {
    if (reader.Read()) {
        result = reader.IsDBNull(0) ? string.Empty : reader[0].ToString();
    }
}

I have some concurrency/deallocation issues in my code and trying to hunt them down.

1
  • where do you capture the concurrency/deallocation issue, is there any stack strace ? Commented May 23, 2012 at 2:27

1 Answer 1

2

Dispose() will be called on the IDataReader automatically, once the end of the using statement goes out of scope. Also make sure that the reader is created with the CommandBehavior.CloseConnection so that the reader will dispose of the connection once it is disposed.

But I don't see any other code involving the connection. If you are using the classic SqlHelper class, that maybe the source of the issue...

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.