Click here to Skip to main content
15,899,314 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Is it necessary to open and close a sql connection for fetching data using data adapter.

Thanks in advance.
Posted

1 solution

No.
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldataadapter.aspx[^]

Note that the code does not explicitly open and close the Connection. The Fill method implicitly opens the Connection that the DataAdapter is using if it finds that the connection is not already open. If Fill opened the connection, it will also close the connection when Fill is finished. This can simplify your code when dealing with a single operation such as a Fill or an Update. However, if you are performing multiple operations that require an open connection, you can improve the performance of your application by explicitly calling the Open method of the Connection, performing the operations against the data source, then calling the Close method of the Connection. You should strive to keep connections to the data source open for a minimal amount of time to free up the resource to be used by other client applications.
Ref:http://msdn.microsoft.com/en-us/library/bh8kx08z(v=vs.71).aspx[^]
 
Share this answer
 
v2
Comments
s.faizaan7 12-Jul-11 3:08am    
Thank you very much..that gave me much clearer understanding.
Prerak Patel 12-Jul-11 3:10am    
You are welcome.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900