473,396 Members | 1,666 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

SqlDataAdapter question

When I use an SqlDataAdapter to fill a DataSet from a database, do I
need to explicitly open and close the SqlConnection that I'm using? For
example, I have code that looks like this:

SqlConnection myConnection = null;
try {
myConnection = new
SqlConnection(ConfigurationSettings.AppSettings["connectionString"]);
SqlDataAdapter myDA = new SqlDataAdapter( sql, myConnection );
// myConnection.Open();
DataTable table = new DataTable();
myDA.Fill( table );
// myConnection.Close();
return table;
}

I'm particularly curious as to whether the SqlDataAdapter is guaranteed
to close automatically, because when I check my MSSQL process info
(after executing all my queries), I find a bunch of excess sleeping
processes and I'm not sure how they got created or why they haven't
been killed.

If anybody has some ideas or help, I'd really appreciate it.

Thanks,

Jay

May 10 '06 #1
1 1181
Hi,

it is guaranteed to handle the connection if you don't open it yourself
(then it would leave it open)

What comes to seeing connections on EM or where you now do that, it is
related to a concept call connection pooling. What you see on list are the
actual physical database connections, and those are pooled in .NET to save
in creating them (as much reuse as possible) so essentially there are
physical connections in the pool even after queries etc would be executed.
There are lower and upper limits for this pool (set within connection
string, and with certain defaults).

Please see: Using Connection Pooling
http://msdn2.microsoft.com/en-US/library/8xx3tyca.aspx

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke

"kempshall" <ja*******@gmail.com> wrote in message
news:11**********************@y43g2000cwc.googlegr oups.com...
When I use an SqlDataAdapter to fill a DataSet from a database, do I
need to explicitly open and close the SqlConnection that I'm using? For
example, I have code that looks like this:

SqlConnection myConnection = null;
try {
myConnection = new
SqlConnection(ConfigurationSettings.AppSettings["connectionString"]);
SqlDataAdapter myDA = new SqlDataAdapter( sql, myConnection );
// myConnection.Open();
DataTable table = new DataTable();
myDA.Fill( table );
// myConnection.Close();
return table;
}

I'm particularly curious as to whether the SqlDataAdapter is guaranteed
to close automatically, because when I check my MSSQL process info
(after executing all my queries), I find a bunch of excess sleeping
processes and I'm not sure how they got created or why they haven't
been killed.

If anybody has some ideas or help, I'd really appreciate it.

Thanks,

Jay

May 10 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Programatix | last post by:
Hi, I'm working on a WebService project. I'm trying to validate data before they are updated to the database by handling the RowUpdating event for a SqlDataAdapter. The data being handled has...
6
by: goodstart123 | last post by:
For example, the following code works fine without SqlConnection. Any Answer to the question? string connectionString = "server=YourServer; uid=sa; pwd=YourPassword;...
3
by: Fernando | last post by:
I am having problems with updating the changes done over a DataSet to a Database. All the changes being done using the Form are stored in the Dataset, but when i decide to close the Form and open...
10
by: Victor | last post by:
Hello there, I have a module in VB.NET (ASP.NET) and on top I declare the SqlConnection and the SqlDataAdapter. Like: Module AccessDB Dim sqlCmd As New SqlCommand Dim conAanvraag As New
7
by: Matt Jensen | last post by:
Howdy Fairly simple question I think, I presume the answer is no it can't be reused for 2 *SELECT* statements, but just hoping for clarification. Just asking in the interests of trying to minimise...
1
by: Ranny | last post by:
Question: What is the process to Insert a record using Dataset and SQLDataAdapter? Explanation: Thanks to Cor I am able to get a record to load, modify it, and save it to the database. My...
1
by: archana | last post by:
hi all I have some doubts related to database handling in .net. I am using sqldataadapter to update and insert rows into database. What i want to know is at a time of inserting rows using...
0
by: dakvanslam | last post by:
I apologize if this is a simple question, but I am very new to SQL Server. I feel like I am missing something easy here. I an running VB ..NET from Visual Studio 2005 and SQL Server Express. The...
2
by: =?Utf-8?B?UGFvbG8=?= | last post by:
I am configuring a SqlDataAdapter as follows: private void ConfigureAdapter(out SqlDataAdapter dAdapt) { dAdapt = new SqlDataAdapter("Select * From Activities", cnString); // Obtain the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.