c# - database is not updating using select and update command in same try block -


here code calls function update data database......

static void main(string[] args)         {             //system.io.streamreader file = new system.io.streamreader(@"c:\users\malik\desktop\research_fields.txt");              //var lines = new system.io.file.readlines(@"c:\users\malik\desktop\research_fields.txt");             program p = new program();             var lines = system.io.file.readlines(@"c:\users\malik\desktop\research_fields.txt");             var dd = new list<tuple<string, double, string>>();              //string document = "the trie data structure has many properties make attractive representing large files of data. these properties include fast retrieval time, quick unsuccessful search determination, , finding longest match given identifier. main drawback space requirement. in paper concept of trie compaction formalized. exact algorithm optimal trie compaction , 3 algorithms approximate trie compaction given, , analysis of 3 algorithms done. analysis indicate actual tries, reductions of around 70 percent in space required uncompacted trie can expected. quality of compaction shown insensitive number of nodes, while more relevant parameter alphabet size of key.";              //string[] document = get_abstract();             //string line;             try             {                 sqlconnection con = new sqlconnection("data source=khizer;initial catalog=subset_aminer;integrated security=true");                  con.open();                 sqlcommand query = con.createcommand();                 query.commandtext = "select p_abstract sub_aminer_paper pid between 1 , 500 , datalength(p_abstract) != 0";                  sqldatareader reader = query.executereader();                  string summary = null;                  while (reader.read())                 {                     summary = reader["p_abstract"].tostring();                     dd.addrange(lines.select(line => tuple.create(line, p.calculate_cs(line, summary), summary)));                      var top_value = dd.orderbydescending(x => x.item2).firstordefault();                      if (top_value != null)                     {                         // record using top_value.item3, , store top_value.item1                         var abstrct = top_value.item3.tostring();                         var r_field = top_value.item1.tostring();                          write_to_database(abstrct, r_field);                     }                 }                 reader.close();                  /* system.io.streamwriter filew = new system.io.streamwriter(@"c:\users\malik\desktop\write_research_fields_temp.txt");                   foreach (var item in d.orderbydescending(t => t.item2))                  {                      filew.writeline("{0} - {1}", item.item2, item.item1);                  }                   filew.close(); */             }             catch (exception e)             {                 console.writeline("exception: " + e.message);             }                         {                 console.writeline("executing block.");              }         }           public static void write_to_database(string document, string research_field)         {              try              {                  string connection = "data source=khizer;initial catalog=subset_aminer;integrated security=true;multipleactiveresultsets=true;";                  using (sqlconnection con = new sqlconnection(connection))                  {                      con.open();                       string query = "select id sub_aminer_paper pid between 1 , 500 , datalength(p_abstract) != 0 , p_abstract @p_abstract";                      using (sqlcommand cmd = new sqlcommand(query, con))                      {                          string st = document;                          cmd.parameters.addwithvalue("@p_abstract", st);                           int id = 0;                          using (sqldatareader reader = cmd.executereader())                          {                              while (reader.read())                              {                                  id = reader.getint32(0);                              }                               reader.close();                               string update_query = "update sub_aminer_paper set research_area = @research_area id = @id";                              using (sqlcommand cmd_update = new sqlcommand(update_query, con))                              {                                  int identity = id;                                  string r_field = research_field;                                   cmd_update.parameters.addwithvalue("@id", identity);                                  cmd_update.parameters.addwithvalue("@research_area", r_field);                                  //cmd_update.commandtimeout = 20;                                  cmd_update.executenonquery();                              }                          }                      }                      con.close();                  }              }              catch (exception e)              {                console.writeline("exception: " + e.message);              }                           {                console.writeline("executing block.");              }          } 

the code looks fine while debugging in between after every execution of cmd_update.executenonquery(); command in write_t0_database() method. blank console screen appears time displays error "exception timeout expired time period elapsed prior completion of operation or server not responding" displays "executing block." again same exception after time again "executing block.". highly appreciated. thanks


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -