-1

I'm developing WPF - EF Core desktop application for multiple users. I have to connect to a MySql server with a limited number of connections. Testing with a single desktop client i see my connections grows 3-4 instances so i'm worry worried about it.

I really dont understand why because my code only calls one instance at the same time.

How i could decrease these numbers? May be MySql maintains a minimun opened connections pool ? Can i force to EF Core to use only one instance for a desktop application instance?

Edit:

It's an Azure MySql database (limited opened connections per instance). I attach an active connections graph. First graphic's part (range values between 4-7) is when i'm using a single desktop user test, then i stop and connections come back to 4.

enter image description here

All my calls are synchronous and with this structure:

using(var context = database.getContext())
{
   //Calls to database
   db.Savechanges(); // if needed
}
user3742379
  • 71
  • 1
  • 6
  • Please show us code so we can understand exactly what you're doing. It could be you should just have a using statement for your dbcontext so it disposes and closes the connection. If you're relying on tracking then you could pass one instance of your dbcontext around in a singleton. I wouldn't usually advise that but you seem to have a specific ( strange ) limitation. – Andy Dec 12 '18 at 12:38
  • It's an Azure MySql database: limited connections – user3742379 Dec 13 '18 at 11:32

1 Answers1

0

Have you tried adding the pooling option to your connection string: pooling=false

var connectionString = "Server=server;Database=database;User ID=user;Password=pass;Pooling=false;";
djones
  • 2,090
  • 1
  • 17
  • 21
  • Just now i've read this tip and seems is not a good solution at all : https://stackoverflow.com/questions/10597051/should-i-use-pooling-false-in-entity-framework-connection-string – user3742379 Dec 13 '18 at 11:38
  • it appears your solution then is to not worry about the 4 active connections. – djones Dec 13 '18 at 14:09