Open Closed

Do we need MultipleActiveResultSets=true in connection string? #1080


User avatar
0
nhontran created
  • ABP Framework version: v3.3.2
  • UI type: Angular
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated (Angular): yes
  • Exception message and stack trace:
  • Steps to reproduce the issue:

Hi, I see the connection string option "MultipleActiveResultSets=true" is put in a lot of articles in documentation but it does not appear in the connection string topic https://docs.abp.io/en/abp/latest/Connection-Strings

Is it required and if yes may I know which functions require it?


2 Answer(s)
  • User Avatar
    0
    alper created
    Support Team Director

    Multiple Active Result Sets (MARS) is a feature that works with SQL Server to allow the execution of multiple batches on a single connection. When MARS is enabled for use with SQL Server, each command object used adds a session to the connection. You can enable it by adding MultipleActiveResultSets=true to the connection string.

    If two batches are submitted under a MARS connection, one of them containing a SELECT statement, the other containing a Data Manipulation Statement, the Data Manipulation Statement can begin execution within execution of the SELECT statement. However, the Data Manipulation Statement must run to completion before the SELECT statement can make progress. If both statements are running under the same transaction, any changes made by a Data Manipulation Statement after the SELECT statement has started execution are not visible to the read operation.

    This says that if you enable MARS your queries will run in parallel and will result in ambitious results if you run in a transaction. MARS operations are not thread-safe.

    There's a very good Microsoft doc on why you need this: https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/sql/enabling-multiple-active-result-sets#special-considerations-when-using-mars

    In general, don't add MARS if you don't know what it does.

  • User Avatar
    0
    nhontran created

    Hi @alper, thanks for the info.

Made with ❤️ on ABP v9.1.0-preview. Updated on November 19, 2024, 12:56