c# - Does multiple query block on single connection(SqlConnection)? -


i have sample data access method design below calls recursively:

public static void deleterecord(sqlconnection connection, string childids, string parentsheetname) {     using (var adapter = new sqldataadapter("...", connection))     {         //fill datatable         string newids = "...";         string newparentname = "...";          const string query = "delete table " +                               "where ids in (@ids) , parent = @parent";         //here's recursion takes place         deleterecord(connection, newids, newparentname);          using (var command = new sqlcommand(query, connection))         {             var parameters = new[] {                  new sqlparameter(...), new sqlparameter(...)             }             command.parameters.addrange(parameters);             command.executenonquery();          }    } 

my questions are:

  1. (as practice) okay pass connection parameter?

  2. is okay put deleterecord method on task each time call it, there's no waiting time command execute query. (of course there's task.waitall(tasks) somewhere)

  3. on scenario number 2, connection block multiple queries sent on server? i've experienced sqlserver suspending queries if has heavy query executing. (connection pooling enabled default, i'm wondering if case here on item 3)

you cannot execute multiple statements concurrently on connection. if want execute multiple statements need use multiple connections. however, in case bad idea. need wrap deletion in transaction maintain database consistency. deleting items on separate connections cannot achieve transactional consistency.

you should think in sets, not items. pass items deleted @ once. see table-valued parameters details how achieve this. use single delete statement joins entire parameter set.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -