Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting "The connection does not support MultipleActiveResultSets" in a ForEach with async-await

I have the following code using Dapper.SimpleCRUD :

var test = new FallEnvironmentalCondition[] {     new FallEnvironmentalCondition {Id=40,FallId=3,EnvironmentalConditionId=1},     new FallEnvironmentalCondition {Id=41,FallId=3,EnvironmentalConditionId=2},     new FallEnvironmentalCondition {Id=42,FallId=3,EnvironmentalConditionId=3} }; test.ToList().ForEach(async x => await conn.UpdateAsync(x)); 

With this code, I am getting following exception:

InvalidOperationException: The connection does not support MultipleActiveResultSets

I don't understand I am awaiting each update so why am I getting this error.

Note: I have no control on the connection string so I can't turn MARS on.

like image 297
MotKohn Avatar asked Sep 11 '17 19:09

MotKohn


1 Answers

You need to add attribute MultipleActiveResultSets in connection string and set it to true to allow multiple active result sets.

 "Data Source=MSSQL1;" & _       "Initial Catalog=AdventureWorks;Integrated Security=SSPI;" & _       "MultipleActiveResultSets=True"   

Read more at: https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/sql/enabling-multiple-active-result-sets

like image 138
vendettamit Avatar answered Sep 19 '22 05:09

vendettamit