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:
(as practice) okay pass connection parameter?
is okay put
deleterecord
method ontask
each time call it, there's no waiting time command execute query. (of course there'stask.waitall(tasks)
somewhere)- 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
Post a Comment