Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to execute several queries asynchronously? #1589

Open
kacpersw opened this issue Dec 4, 2020 · 1 comment
Open

Is it possible to execute several queries asynchronously? #1589

kacpersw opened this issue Dec 4, 2020 · 1 comment

Comments

@kacpersw
Copy link

@kacpersw kacpersw commented Dec 4, 2020

I have trouble executing several queries simultaneously (asynchronously). I am getting an error related to executing several actions simultaneously.
Stack: .NET 5, MS SQL, Dapper 2.0.78

var task =  connection.QueryAsync<string>("SELECT...");
var task2 = connection.QueryAsync<string>("SELECT...");
var task3 = connection.QueryAsync<string>("SELECT...");
await Task.WhenAll(task, task2, task3);

In connection string I set MultipleActiveResultSets=False and I don't want to change it to True.
It's the error:
System.InvalidOperationException: The connection does not support MultipleActiveResultSets.\r\n at Microsoft.Data.SqlClient.SqlCommand.

Is there a solution in the Dapper to execute several queries asynchronously?

@NickCraver
Copy link
Member

@NickCraver NickCraver commented Dec 4, 2020

This isn't a Dapper issue, but a SQL Client/Server one in general. You'll need to enable it in the connection string, and note that there is some performance overhead to doing so (that's why it's not enabled by default). Here's how: https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/sql/enabling-multiple-active-result-sets

@kacpersw kacpersw closed this Dec 4, 2020
@kacpersw kacpersw reopened this Dec 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.