I'm using Dapper with asp.net core and I'm trying to enable Multiple Active Result
Did anyone managed to enable MARS using Dapper?
I tried to append to the connection
"MultipleActiveResultSets=True" but with no effect.
The error that I'm getting is
InvalidOperationException: The connection does not support MultipleActiveResultSets
The only slight connection Dapper has to MARS is when using the overlapped async API to issue multiple in-flight operations with
ExecuteAsync, and have told it that you want to by configuring
CommandDefinition. Other than that: Dapper doesn't care about MARS. If you enable it on your connection: it will be enabled; if you don't: it won't. The key thing that won't work without MARS is: using an unbuffered query (
Query<T>(...buffered: false)) and then issuing additional operations inside that query. But that is usually avoidable by simply: not doing that. You can also enable MARS on your connection string, but frankly I generally advice against that.
So: Dapper has no explicit controls related to MARS except for in the case of
MultipleActiveResultSets=True is an ADO.Net configuration, it has nothing to do with the Dapper, it is meant to carry out overlapped batch operation on a Single live connection, check link for more information.
In case your aim is to receive multiple result sets in a single execution, then that has nothing to do with MARS and is enabled by default. Doing it using Dapper you need to use
QueryMultiple to fetch the
GridReader, which can help fetch multiple result sets, check Dapper Query Multiple. In plain vanilla ADO.Net for same purpose, you need to use
DataReader.NextResult for the connected architecture and Dataset for disconnected architecture for fetching multiple result sets