Reputation: 13769
My form calls multiple TableAdapter
objects to fill a local, common DataSet
with relevant rows (see below).
private void frm_TrialsFromOrder_Load(object sender, EventArgs e)
{
this.trialTableAdapter.FillBy(this.myDataSet.trialTable, this.trial_id);
this.orderTableAdapter.FillBy(this.myDataSet.orderTable, this.order_id);
}
When executing the program, the SQL Server Profiler shows:
How can I configure multiple TableAdapter
objects to use the same SqlConnection
?
Upvotes: 1
Views: 224
Reputation: 67918
You don't want to. The SqlConnection
object is built to be created, inside of a using
as a best practice, used, and then disposed (hence the using
statement). Do not share connection objects. The operation of pooling connections to ensure that it's not expensive is handled by the server.
Per MSDN:
To ensure that connections are always closed, open the connection inside of a using block, as shown in the following code fragment. Doing so ensures that the connection is automatically closed when the code exits the block.
Do make sure you're setting the Pooling
property on the connection string to true
so that pooling is enabled; that would defeat the purpose otherwise (in general).
Upvotes: 2