0

I have some functions that connect to the database. For example : function with adds a new user after registration :

public void AddUser(UserModel user)
{
using (MySqlConnection connection = new MySqlConnection(this.ConnectionString))
        {
            connection.Open();
            MySqlCommand cmd = connection.CreateCommand();
            cmd.CommandText = "insert into users (login , password , email ) values (@name , @password , @email)";
            cmd.Parameters.AddWithValue("@name", user.Name);
            cmd.Parameters.AddWithValue("@password", user.Password);
            cmd.Parameters.AddWithValue("@email", user.Email);         
            cmd.ExecuteNonQuery();
            connection.Close();
        }
}

I have more similar functions that invoke almost at the same time. When i run application I have a MySqlException : "Too many connections". I set max_connections to 100000 in my database and i set Pooling=false in connection string but it doesn't change anything.

gilos
  • 21
  • 3
  • I would suggest wrapping `cmd` with `using`. Although to be honest I doubt that is the cause. – mjwills Jul 01 '18 at 13:57
  • 1
    Are you sure that all other codes access the MySqlConnection inside a using statement? – Steve Jul 01 '18 at 13:57
  • there are other reasons you could get this error, including hardware related issues with space. check out this answer https://stackoverflow.com/a/34176072/5463252 – Hack Jul 01 '18 at 14:03
  • MySql use a fle with Extension .SDF. There is no server so you can have issues when multi-users access the database. It is better that you use a SQL Server which is designed for multi-users. The SDF file has to be shared if more than one use is accessing the file (not a real database). – jdweng Jul 01 '18 at 18:27
  • Mysql works just fine in multiuser situations and has a server also,I use it.that noted,try setting.i doubt your issue is to do with connection check the drive space,set global max_connection to 1000 works for me.stop server then start it. – Peter Jul 01 '18 at 20:01
  • Thanks for help, i will use SQL instead MySQL next time. – gilos Jul 02 '18 at 15:06

0 Answers0