Dapper.DataRepositories icon indicating copy to clipboard operation
Dapper.DataRepositories copied to clipboard

Reusing Connection Causes Errors

Open Mx-Boyan opened this issue 10 years ago • 2 comments

When re-using the same SQL connection for more than one data reader for the same command, the query fails with DataReader already open.

Mx-Boyan avatar Feb 27 '15 20:02 Mx-Boyan

I think that's something handled by the base Dapper library instead of my extension.

Yoinbol avatar Mar 09 '15 04:03 Yoinbol

I don't think it is handled by Dapper internally, just look at all the examples of using Dapper. It doesn't care about opening or closing the connections, you are responsible for setting that up. The issue with your repository implementation is that you setup the connection once (inside the constructor) and re-use it for every call, instead of setting it up before you call dapper and then disposing it. I can create a fork and a submit a PR if you want to see what I mean.

Mx-Boyan avatar Mar 09 '15 22:03 Mx-Boyan