c# - Why the SQL Server error when many clients are trying to write to a table? -
i have simple program on 200 machines logs form user opening. everytime form open sql connection opened, row inserted , guess connection closed ? read connection pooling on default guess not closing ? not allowed call web service or potential better way question why error , there , idea how fix ? or on sql end ? maybe setting can try changing ?
using (sqlconnection connection = new sqlconnection(connectionstring)) { try { connection.open(); using (sqlcommand command = new sqlcommand( "insert loggerloanform values(@session, @form, @datestamp, @loannumber)", connection)) { command.parameters.add(new sqlparameter("session", llf.sesssionid)); command.parameters.add(new sqlparameter("form", llf.form)); command.parameters.add(new sqlparameter("datestamp", llf.datestamp)); command.parameters.add(new sqlparameter("loannumber", llf.loannumber)); command.executenonquery(); } } catch (exception ex) { appinsighthelper.trackexception(ex); } }
a network-related or instance-specific error occurred while establishing connection sql server. server not found or not accessible. verify instance name correct , sql server configured allow remote connections. (provider: tcp provider, error: 0 - requested name valid, no data of requested type found.)the requested name valid, no data of requested type found
the error seems happen more during peak hours guess there not enough open connections or sql server?
how retry
const int max_try = 5; int = max_try; while (i-- > 0) { using (sqlconnection connection = new sqlconnection(connectionstring)) { try { connection.open(); using (sqlcommand command = new sqlcommand( "insert loggerloanform values(@session, @form, @datestamp, @loannumber)", connection)) { command.parameters.add(new sqlparameter("session", llf.sesssionid)); command.parameters.add(new sqlparameter("form", llf.form)); command.parameters.add(new sqlparameter("datestamp", llf.datestamp)); command.parameters.add(new sqlparameter("loannumber", llf.loannumber)); command.executenonquery(); = 0; } } catch (exception ex) { if (i == 0) appinsighthelper.trackexception(ex); system.threading.thread.sleep(50); } } }
Comments
Post a Comment