Maximum pool size error in C# using MySQL -


do have suggestion on how manage application run properly? updates rows (203 rows can more) in table of database. , need run day. after hour of running, prompts error:

mysqlexception: error connecting: time out expired. timeout period elapsed prior , max pool size reached obtaining connection pool. may have occurred because pooled connection in use.

i close connection using conn.close().

i'm not sure if increasing pool size best solution since run day , possibly may reach pool size set.

here's code:

public static class globals  {     //global variable     public static string update;     public static string update2;     public const string connectionstring = "server=localhost; uid=root; pwd=; database=it_map;";     public static int totalruntime = 0; }  static void main(string[] args)  {     while (true)     {         stopwatch stopwatch = new stopwatch();         stopwatch.start();          thread t = new thread(new threadstart(pinglaptop));         thread t2 = new thread(new threadstart(pingdesktop));         //thread t3 = new thread(new threadstart(pingphone));         //thread t4 = new thread(new threadstart(pinglaptop));          console.writeline("\nupdating status...\n");          t.start();         t2.start();         //t3.start();         //t4.start();          t.join();         t2.join();         //t3.join();         //t4.join();          stopwatch.stop();         // elapsed time timespan value.         timespan ts = stopwatch.elapsed;          // format , display timespan value.         string elapsedtime = string.format("{0:00}:{1:00}:{2:00}.{3:00}", ts.hours, ts.minutes, ts.seconds, ts.milliseconds / 10);         console.writeline("\nruntime " + elapsedtime);          console.writeline("\nnext run start after 1 second...");         thread.sleep(1000);     } }  static void pinglaptop()  {      string sql = "select * tbl_units category=\"laptop\"";     mysqlconnection conn, conn2;      mysqlcommand command, command2;     mysqldatareader reader;     pingreply reply;     ping myping;     string netbios_name;      try      {         conn = new mysqlconnection(globals.connectionstring);         command = new mysqlcommand(sql, conn);         conn.open();          reader = command.executereader();         while (reader.read())          {                 myping = new ping();                 netbios_name = reader.getstring("netbios_name");                 console.writeline("laptop: " + netbios_name);                 try {                     reply = myping.send(netbios_name, 2000);                     if (reply != null) {                         string status = reply.status.tostring();                          //updates 'status' of unit in database                         console.writeline(netbios_name + " status: "+status);                         if(status.equals("success")) {                             globals.update = "update tbl_units set status=\"online\" netbios_name = @name";                         }                         else if (status.equals("timedout")) {                             globals.update = "update tbl_units set status=\"offline\" netbios_name= @name";                         }                          //builds connection database                         using (conn2 = new mysqlconnection(globals.connectionstring)) {                             command2 = new mysqlcommand(globals.update, conn2);                             command2.parameters.addwithvalue("@name", netbios_name);                             conn2.open();                             command2.executenonquery();                                                   }                      }                 }                 catch (pingexception e) {                     console.writeline("status: host unreachable.");                      globals.update = "update tbl_units set status=\"x\" netbios_name= @name";                     using (conn2 = new mysqlconnection(globals.connectionstring)) {                         command2 = new mysqlcommand(globals.update, conn2);                         command2.parameters.addwithvalue("@name", netbios_name);                         conn2.open();                         command2.executenonquery();                                           }                 }             }         }         catch (mysqlexception ex)         {             console.writeline("laptop");             console.writeline(ex.tostring());         }      } 

i'm using using() instead of conn.close. have function pingdesktop, same different query.

you didn't close

conn.open(); 

add conn.close in try-catch's finally

finally {      conn.close();                 } 

add max pool size in connection string

like this

public const string connectionstring = "server=localhost; uid=root; pwd=; database=it_map;max pool size=5;"; 

Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -