Gerald Hughes
Gerald Hughes

Reputation: 6159

Enabling Multiple Active Result Sets using Dapper

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.

Enabling Multiple Active Result Sets

The error that I'm getting is

InvalidOperationException: The connection does not support MultipleActiveResultSets

Upvotes: 6

Views: 6587

Answers (2)

Mrinal Kamboj
Mrinal Kamboj

Reputation: 11478

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

Upvotes: 3

Marc Gravell
Marc Gravell

Reputation: 1062995

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 Pipelined to true on 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 ExecuteAsync with Pipelined enabled.

Upvotes: 13

Related Questions