c# - Ensure DB connection is closed on Background worker Cancel Async -


i have code far background worker run background worker:

if (backgroundworker1.isbusy == true) {     backgroundworker1.cancelasync(); } else {     backgroundworker1.runworkerasync(); } 

will close out connection in backgrounder worker well? or need add lines of code progress change?

private void backgroundworker1_dowork(object sender, doworkeventargs e) {             try             {                 superset = new dataset();                 connectionstring = "driver={ibm db2 odbc driver}; database=" + lines[i] + "; hostname=" + lines[i] + "." + lines[i] + ".xxx; port = xxxx; protocol = tcpip; uid=xx; pwd= xxxx;             }             connection = new odbcconnection(connectionstring);             adapter = new odbcdataadapter(masterquery, connection);              connection.open();             adapter.fill(superset);             superset.merge(superset);             connection.close();         }     }     datagridview1.datasource = superset;     datagridview1.datasource = superset.tables[0];     //tabcontrol1.selectedtab = tabpage3; } 

the connection doesn't close, abort worker connection might stuck inside it,

why don't make simple? call

connection.close(); connection.dispose(); 

after call cancelasync


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -