C# MySQL in multithreaded application -


i've developed emulation program game. program works mysql database communication. have tried use idisposable method (which suggested everyone), allocate mysql connection thread, when specific thread requires database. however, when server reaches on 400 users, mysql server gets overloaded requests. have tried pooling option (size: min 0, max. 150) - resulted same issue.

currently, using locking provide parallelism system. system works static objects (static connection object) manage whole server (i think affects performance offered multithreading though).

public static boolean query(ref mysqldatareader resource, string query) {     lock (connection)     {         mysqlcommand cmd = new mysqlcommand(query, connection);          try         {             resource = cmd.executereader();         }         catch (mysqlexception exception)         {              console.writeline("mysql error: " + exception.message);              return false;         }          return true;     } } 

a method works "query" method.

public static string getobjectproperty(                  string field, string identifier,                   boolean primary = true, string table = "accounts") {     string fieldvalue = null;     try     {         lock (generaldb.connection)         {             mysqldatareader datareader = null;             if (generaldb.query(                           ref datareader,                            "select " + mysqlhelper.escapestring(field) +                            " " + table +                            " " + (primary ? "id" : "name") + " = '" +                            mysqlhelper.escapestring(identifier) + "';") == false)             {                 return null;             }             if (datareader == null) return null;             while (datareader.read())                  fieldvalue = datareader[0].tostring();             datareader.close();             return fieldvalue;         }     }      catch (exception exception)     {         return fieldvalue;     } } 

i desperately need suggestions. thanks.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -