Does anyone know of any disadvantages of MARS (Multiple Active Result Sets)? Does anyone know of any reason why one should avoid using MARS, like cases where cursors are more useful then MARS.
3 Answers
There are apparently at least two known (potential) drawbacks (from this (1) Team blog):
Obviously this can cause potential problems for any legacy systems which weren't designed to run against a MARS enabled design - "existing code optimized to run in the non-MARS world may show a slight performance dip when run un-modified with MARS"
“With MARS you can send multiple multi-statement batches to the server. The server will interleave execution of such batches, which means that if the batches change server state via SET or USE statements, for example, or use TSQL transaction management statements (BEGIN TRAN, COMMIT, ROLLBACK), both you and the server can get confused about what your actual intent is.”
I've yet to try out a MARS enabled design, but I'm coming very close to doing so on my current project. We have a slight issue with competing (and sometimes dependent) query operations (like lazy loading configuration data out of the same database that an active recordset is executing).
There's more information on the MSDN site (2) here
[ (1) https://web.archive.org/web/20190911155929/https://blogs.msdn.microsoft.com/sqlnativeclient/2006/09/27/using-mars-with-sql-native-client/ ]
[ (2) http://msdn.microsoft.com/en-us/library/ms131686.aspx ]
-
3Before applying @RobS great solution, I'd read this article first to assure you can't solve this issue with the following solution: http://devproconnections.com/development/solving-net-scalability-problem OR adding .ToList() to the end of your DB call, which solved my problem. Btw, Thanks RobS for the great advice, MARS will come in handy in the future. :) – Termato Aug 21 '14 at 18:24
- It takes slightly more server resources than doing one connection at a time.
- You have to be running SQL Server 2005 or later. So that can be a problem in legacy (ack!) environments.

- 95,573
- 20
- 147
- 170
-
-
21How much is "slightly more server resources"? Can you put an estimate on it in terms of memory or CPU? I am interested in this mainly because I am in an Azure environment where resources are proportional with the cost of the server. – Mathias Lykkegaard Lorenzen Jan 06 '14 at 01:44
-
1@MathiasLykkegaardLorenzen Did you ever discover the answer to your question? – Sinjai Oct 05 '18 at 17:39
depending on what? there are no real disadvantages.
they don't support Transaction savepoints. but i don't think of this as a disadvantage.

- 15,457
- 2
- 43
- 51
-
1That's a major disadvantage! The whole point of transactions is rollbacks and save points, the lack of this makes MARS pretty useless in professional applications. Anything that can potentially cause data corruption or prevent data recovery should be avoided! – MC9000 Mar 01 '23 at 13:07