How goes it everybody?
Very simple question today. If I give two separate Threads two different SqlCommands. If both SqlCommands use the same SqlConnection, can they execute at the same time? Does SqlConnection block this behavior? Or does something… more interesting happen?
(I do believe SqlConnections are pooled by connection string for this exact reason, but I just need some reassurance)
This is a hypothetical question, just curious how SqlConnection behaves given the design described.
With ADO.NET connection pooling in place, the proper way to run a query is to create and open a connection object, then run a command object (which uses the connection object), and then close the connection. So the scenario you describe (where you hand an open connection to two different command objects) should never occur. In normal usage your two different command objects should open and close their own connection objects independent of each other, which means you will never run into the problem of two command objects simultaneously attempting to use the same connection at the same time.