Question Use of MARS

andrewmanuja

Well-known member
Joined
May 30, 2019
Messages
75
Programming Experience
Beginner
Hi,
This is more related to SQL and apologies in advance . However, since I need to clarify this, thought of posting this under the general discussion.

I got an issue while trying to execute multiple INSERT queries to SQL database.
The error was, "There is already an open DataReader associated with this Command which must be closed".

When doing a bit of reading, I came across the addition of MARS in to the DB connection string as a solution and it worked.

My question is, the application I am developing is intended to allow multiple users to interact with the application at the same time, and the use of MARS will affect the performance? or will it create any impact on the application? or should I use an alternative solution to get rid of the said issue?

Appreciate your feedback.

Kind regards,

Andrew
 
You should do some reading on MARS:


In general though, it's not going to cause any performance or other issues.
 
The issue you reported is from mismanaged SQL connections. Consider writing some type of SQL helper class which will manage your connections for you. Doing so will reduce the amount of errors your app is experiencing.

Look into connection pooling... the use of using blocks on your code will also help to dispose of anything and everything used within them. If the object you work with implements IDisposable, you are best to dispose of it as soon as you are done using it. The best way to do that is to enclose it with a using block. You can find more information on them in my signature.
 
Back
Top Bottom