Question Use of MARS

andrewmanuja

Active member
Joined
May 30, 2019
Messages
28
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
 

Sheepings

Senior Programmer
Joined
Sep 5, 2018
Messages
166
Location
UK
Programming Experience
10+
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.
 
Top Bottom