C# MySQL Select into Var -> Memory increasing -


i new c# , trying read value out of mysql database.

what single number. store int variable , check specific numbers activate functions of kuando busylight.

the whole thing looped (tried while (true) {} , goto methods).

it works far, memory usage increasing. starting @ ~6 mib...30mib , on.

somehow saves data process did not find out how clear used memory.

as said im very new this, maybe code toooooo crappy work fine , problem of clearing unused data. tell me :d

thank much!

using system; using system.collections.generic; using system.linq; using system.text; using mysql.data.mysqlclient; using plenom.components.busylight.sdk; using system.threading;  namespace tanss4bll {     class program     {         static void main()         {                 var controller = new busylightuccontroller();                 int resultstatus;                 while (true)                 {                  string sqldatabaseselect = "select typid az_manager maid = 4328 order datum desc limit 1";                  string connectionstring = "server=localhost; database=tanss; uid=root; pwd=password";                   using (mysqlconnection conndatabase = new mysqlconnection(connectionstring))                  {                         conndatabase.open();                         mysqlcommand cmd = new mysqlcommand(sqldatabaseselect, conndatabase);                         resultstatus = (int)cmd.executescalar();                          if (resultstatus == 1)                         {                             //console.writeline("debugtext1");                                                           controller.light(busylightcolor.green);                          }                         else if (resultstatus == 2)                         {                             //console.writeline("debugtext2");                              controller.light(busylightcolor.red);                         }                         else if (resultstatus == 3)                         {                             //console.writeline("debugtext3");                              controller.light(busylightcolor.red);                         }                         else if (resultstatus == 9)                         {                             //console.writeline("debugtext4");                              controller.light(busylightcolor.red);                         }                         conndatabase.close();                    }                 //console.writeline(resultstatus);                 thread.sleep(1000);                 //console.clear();               }         }                  } } 

you creating multiple connections database while(true) loop.

string connectionstring = "server=localhost; database=tanss; uid=root; pwd=password";

this line can move out of while loop , should problem.

also, if turns production code, need set parameters when working database. parameters how avoid sql injection.

avoiding sql injection

hopefully helps out!


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

How to get multiresult with multicondition in Sql Server -