-1

I have a function that receives parameters (schema name, column name etc) and updates a Mysql table, the problem is that when I use two Mysql commands inside this function (below), one to set the schema and one to update the table, the Close connection command at the end `(conDataBase3->Close();) does not work.

I am checking the number of open connections in the Mysql console (SHOW FULLPROCESSLIST) before and after running the function. any solutions or explanations? thanks

int simple_1::update_table_with_value(gcroot<String^ > schema, gcroot<String^ > table_name, int numerator, gcroot<String^ > field_to_update, double value_to_update)

{

    gcroot<MySqlConnection^ > conDataBase3;
    conDataBase3 = gcnew MySqlConnection(constring);
    conDataBase3->Open();

    try{



        String ^ schema_name = "Use " + schema + " ;";
        MySqlCommand ^cmdDataBase3 = gcnew MySqlCommand(schema_name, conDataBase3);
        MySqlCommand ^cmdDataBase4 = gcnew MySqlCommand(schema_name, conDataBase3);

        cmdDataBase3->ExecuteNonQuery();

        String ^ temp1 = "UPDATE ";
        String ^ temp2 = table_name;
        String ^ temp3 = " SET ";
        String ^ temp4 = field_to_update;
        String ^ temp6 = "=(@value1)  WHERE numerator = (@value2)";

        String ^ temp8 = temp1 + temp2 + temp3 + temp4 + temp6;


        // end of the writing part

        cmdDataBase4 = gcnew MySqlCommand(temp8, conDataBase3);
        cmdDataBase4->Parameters->AddWithValue("@value1", value_to_update);
        cmdDataBase4->Parameters->AddWithValue("@value2", numerator);
        cmdDataBase4->Prepare();
        cmdDataBase4->ExecuteNonQuery();



    }//try
    catch (Exception^ ex)
    {
        System::Windows::Forms::MessageBox::Show(ex->Message);
    }
    conDataBase3->Close();

    int answer = 0;
    return (answer);
}
Laura Tom
  • 9
  • 3
  • Do you mean `&` instead of `^`? – tadman Jun 26 '15 at 19:46
  • I see code here https://social.msdn.microsoft.com/Forums/vstudio/en-US/15f0507f-0542-4966-8efe-a24e80757c09/connecting-to-a-database-in-mysql-cli That does a delete stmt and delete con at end of a fcn hopefully useful – Drew Jun 26 '15 at 20:00
  • the example you refer to uses the c++ connector not the .net connector, here is an example to the C++ connector http://stackoverflow.com/questions/16424828/how-to-connect-mysql-database-using-c – Laura Tom Jun 26 '15 at 20:56

1 Answers1

0

ok found the answer, I needed to disable the pooling option otherwise closing the connection still keeps the socket open..

found it here: http://bugs.mysql.com/bug.php?id=24138 see the last 2 lines.

The way to disable the pooling : http://www.connectionstrings.com/mysql-connector-net-mysqlconnection/disable-connection-pooling/

Laura Tom
  • 9
  • 3