mysql - C# - SQL Database - Sending query to update records however too many update requests cause some to get missed -


i've searched high , lo, apologies if have missed something.

when run source, no errors arise , looks if working should, when inspect database, records have been updated/added , others have been missed.

the rate of updates varies between 1 per second upwards of 25 per second (some headroom/just incase, typically around 15).

in section, query database pull existing values, make adjustments on values, save database.

below snippet updates sql database, there 43 columns being updated (some may remain same value, being re-added).

is there way can ensure update requests pass through , succeed in updating?

try {     mysqlcommand cmd2 = connection.createcommand();     connection.open();     cmd2.commandtype = commandtype.text;     cmd2.commandtext = "update user_information set examplevalue = @examplevalue username = @username";     cmd2.parameters.addwithvalue("@username", username);     cmd2.parameters.addwithvalue("@examplevalue", examplevalue);      cmd2.executenonquery();     connection.close(); } catch (exception ex) {     throw; } {     if (connection.state == connectionstate.open)     {         connection.close();         //this.loaddata();     } } 

for better comparison, use ltrim & rtrim i-e ltrim(rtrim(username)) in sql , in c# use string.trim() i-e usename.trim()

ltrim(rtrim(username)) remove spaces of username in database eg. ' smith ' -> 'smith' , username.trim() remove spaces of input

so replace lines

cmd2.commandtext = "update user_information set examplevalue = @examplevalue username = @username"; cmd2.parameters.addwithvalue("@username", username); 

with

cmd2.commandtext = "update user_information set examplevalue = @examplevalue ltrim(rtrim(username)) = @username"; cmd2.parameters.addwithvalue("@username", username.trim()); 

to avoid case sensitive comparison, use lower i-e lower(username) in sql , in c# use string.tolower(), username.tolower()

now, code that

cmd2.commandtext = "update user_information set examplevalue = @examplevalue lower(ltrim(rtrim(username))) = @username"; cmd2.parameters.addwithvalue("@username", username.trim().tolower()); 

Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -