c# - Concurrent users on Application result in MySQL Database Error -
i have c# web application connects mysql database. when multiple users access site @ same time see "there open datareader associated command must closed first" error. application works fine when 1 person accessing site.
i found multiple articles sited multipleactiveresultsets=true in connection string, applies sql server not mysql.
i traced error runsql function handles bulk of database queries unable find solution.
this straight forward function, takes raw sql code, list of parameters, enum translates 1 of many possible database connection strings, , bool determines if need set transaction.
i @ loss.
public datatable runsql(string querystr, list<mysqlparameter> parameters, connectiontype connection, bool transaction) { datatable results = new datatable(); mysqlconnection con = new mysqlconnection(getconnection(connection)); mysqltransation trans; mysqlcommand command; con.open(); //if transaction requested, tie 1 query if(transaction) { trans = con.begintransaction(); command = new mysqlcommand(querystr, con, trans); } else { command = new mysqlcommand(querystr, con); } //if parameters provided add them query if(parameters.count > 0) foreach(mysqlparameter parm in parameters) command.parameters.add(parm); try { //send command , results mysqlreader rdr = command.execurereader(); //populate column names string columnname; type type; foreach(dataviewrow row in rdr.getschematable().defaultview) { columnname = row["columnname"].tostring(); type = (type)row["datatype"]; results.columns.add(columnname, type); } //populate results results.load(rdr); //so far good, close transaction if 1 requested if(transaction) { command.transaction.commit(); } con.close(); } catch (exception up) { //something bad happened, rollback if there transaction if(transaction) { command.transaction.rollback(); } con.close(); //report error handling @ source. throw up; } return results; }
concurrency in mysql nightmare. sorry start out this, if @ possible should port mssql since using c# , integrates easily.
concurrency poor when using myisam mysql database engine. first, , large red flag, myisam does not support transactions. means cannot change isolation levels of reads or updates. second, , related first, using read on table issues low level table lock. however, in order update occur, must have exclusive table lock, , else (even low level) prevent happening , go lock queue.
there no fixing because design.
Comments
Post a Comment