3

I would like to know about Multiple Active Result Sets I have read Microsoft documentation, but I didn't understand it very well if you can add some example about MultipleActiveResultSets.

When MARS is enabled for use with SQL Server, each command object used adds a session to the connection. I didn't understand it.

In general, When should I use "MultipleActiveResultSets" in the connection string?

For instance, I have used this code for the Migrating database, but I got me some error.

Keyword not supported: "MultipleActiveResultSets"

  public static void Main(string[] args)
        {
            var host = CreateHostBuilder(args).Build();
            using(var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;
                try
                {
                    var context = services.GetRequiredService<DataContext>();
                    context.Database.Migrate();
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService<ILogger<Program>>();
                    logger.LogError(ex, "An error occured during migration.");
                    
                }
            }
            host.Run();
        }

{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft": "Warning",
      "Microsoft.Hosting.Lifetime": "Information"
    }
  },
  "AllowedHosts": "*",
  "ConnectionStrings":{
      "DBConnection": "server=.;database=ReactivityDB;MultipleActiveResultSet=true;Trusted_Connection=True"
  }
    

}

Hans Kesting
  • 38,117
  • 9
  • 79
  • 111
Behnam
  • 359
  • 1
  • 5
  • 13
  • Your sample code needs to include where you specify `multipleactiveresultset` – Elaskanator Nov 08 '19 at 15:55
  • You only use it when you have to, which is almost certainly not in a migration. – stuartd Nov 08 '19 at 15:56
  • Is this specific to entity framework? How did 'multipleactiveresultset' get into the connection string, was it something you added or in existing code? – d219 Nov 08 '19 at 15:56
  • @Elaskanator I added my connection string code from appsettings.json – Behnam Nov 08 '19 at 15:59
  • Possible duplicate of [Intermittent error with EF Core: The connection does not support MultipleActiveResultSets](https://stackoverflow.com/questions/46033645/intermittent-error-with-ef-core-the-connection-does-not-support-multipleactiver) – d219 Nov 08 '19 at 16:13

1 Answers1

3

According to your error message:

Keyword not supported: 'multipleactiveresultset'

and your connection string:

...database=ReactivityDB;MultipleActiveResultSet=true...

that keyword should be in plural form:

...database=ReactivityDB;MultipleActiveResultSets=true...
LarsTech
  • 80,625
  • 14
  • 153
  • 225