Connection to SQL Server 2005
Posted on 2006-11-16
I have a C# windows form application and I connect to SQL server 2005 using two methods:
SqlCommand cmd = new SqlCommand("select ...", sqlConnectionObject);
SqlDataAdapter mDA = new SqlDataAdapter(("select ...", "Data Source...");
A process is created in SQL server after the first method is called. I have used a single object to limit
the connection. Now, when I called the second method, a new process is created. As a result, there
are two processes for each application in the SQL server!
For SqlDataAdapter, I understand that C# will open a connection if it is not connected,
and closed automatically after use.
C# will remain connect if there is already an opened connection after use.
How can I limit my application to have only one connection in the SQL server?