DBCommand using block -


i have following code:

using (mysqlconnection conn = new mysqlconnection(connstr)) {     conn.open();      cmd = conn.createcommand();     cmd.commandtext = "select * events";     cmd.commandtype = commandtype.text;     cmd.executenonquery(); } 

from reading few articles on site, suggested dbcommand should in using block, however, can't see why needed. connection closed, dbcommand holding on requires using block? case if class inherits idisposable must use using block or manually called dispose?

i ran simulator 100 threads on code above, , code using block on dbcommand , see no real differences in memory usage.

dbcommand abstract, , not presuppose native resources vendor-specific subclass hold, , in order should released. proper nesting of using blocks seems reasonable implicit coding convention.


Comments

Popular posts from this blog

How to provide Authorization & Authentication using Asp.net, C#? -

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

How to use Authorization & Authentication in Asp.net, C#? -