TGPChris Posted April 26, 2005 Posted April 26, 2005 I have an application that is used daily by 20 people - each person runs the app on their own computer. It is entirely DB-driven (yeah, what's not). Is it better to open the DB connection on program load and keep open until the application is closed OR Is it better to open/close the connections only when needed? What's better and what is the reason? Quote
bri189a Posted April 26, 2005 Posted April 26, 2005 DBA's don't like connections tied up for no reason. Open and close only when needed. Use disconnected data as much as possible (DataSet). Quote
Administrators PlausiblyDamp Posted April 26, 2005 Administrators Posted April 26, 2005 If you are developing a web application then the client machines shouldn't be having any connections to the DB itself - the web server would be the only computer connecting direct to the database anyway. However as bri189a says - only connect as and when you need, release connections as soon as possible and try to work in a disconnected fashion when possible. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Mister E Posted April 26, 2005 Posted April 26, 2005 Do what PlausiblyDamp said and also understand that something like the .NET Framework has robust connection pooling for databases. You may *think* that you're opening up a new connection when, in reality, you're just using one that is currently in use. The handoff occurs seamlessly to you and is handled by the framework. So, in the end, the best practice is the open and close things as you need them. Quote
HJB417 Posted April 27, 2005 Posted April 27, 2005 Do what PlausiblyDamp said and also understand that something like the .NET Framework has robust connection pooling for databases. You may *think* that you're opening up a new connection when' date=' in reality, you're just using one that is currently in use. The handoff occurs seamlessly to you and is handled by the framework. So, in the end, the best practice is the open and close things as you need them.[/quote'] the .net framework doesn't do/support connection pooling. It's something the dataprovider needs to implement such as the ms sql managed driver/provider that ships w/ the .net framework. Quote
Mister E Posted April 27, 2005 Posted April 27, 2005 the .net framework doesn't do/support connection pooling. It's something the dataprovider needs to implement such as the ms sql managed driver/provider that ships w/ the .net framework.The System.Data.SqlClient class is not simply a driver that "ships" with the Framework. It is part of the Framework or, as Microsoft puts it, "The System.Data.SqlClient namespace is the .NET Framework Data Provider for SQL Server." So, as I said, the framework supports connection pooling. If you use a third-party driver you are, obviously, going to be limited to the capabilities of that driver. Quote
HJB417 Posted April 27, 2005 Posted April 27, 2005 you shouldn't assume everyone uses sql server and your statement, the 1 I quoted, is amgigous. Maybe you should say "has robust connection pooling for ms sql databases" or " the sqlconnection class supports connection pooling". Only after my reply do you state "If you use a third-party driver you are, obviously, going to be limited to the capabilities of that driver.". Quote
Mister E Posted April 27, 2005 Posted April 27, 2005 you shouldn't assume everyone uses sql server and your statement' date=' the 1 I quoted, is amgigous. Maybe you should say "has robust connection pooling for ms sql databases" or " the sqlconnection class supports connection pooling". Only after my reply do you state "If you use a third-party driver you are, obviously, going to be limited to the capabilities of that driver.".[/quote'] There are no ambiguities. I simply said that the ".NET Framework has robust connection pooling for databases". The SqlClient class is part of the framework. The SqlClient class supports connection pooling. Therefore the .NET Framework supports connection pooling. That's it, nothing more, nothing less. You needlessly chimed in to say that the .NET Framework "doesn't do/support connection pooling". Which, as I have pointed out, is dead wrong. PS -- The System.Data.OleDb class also supports connection pooling. Quote
penfold69 Posted April 27, 2005 Posted April 27, 2005 And in addition, the MySql.Data.MySqlClient also supports connection pooling, and follows the IDBConnector/IDBCommand interfaces, so is 100% compatible with the SqlClient libraries Although I do acknowledge what HJB417 says - it *IS* provider dependant, but any drivers that ship *as part* of the framework *do* support pooling by default. B. Quote
Mister E Posted April 27, 2005 Posted April 27, 2005 I should clarify. System.Data.OleDb and System.Data.SqlClient are namespaces not classes. OleDbConnection and SqlConnection are the respective classes that support connection pooling within those namespaces. Quote
TGPChris Posted April 27, 2005 Author Posted April 27, 2005 Thanks, all your replies were VERY helpful. Time for me to change some code... Quote
bri189a Posted May 2, 2005 Posted May 2, 2005 Yeah, ODBC when used with AS400... no built in connection pooling there...really wish it did though, let me tell ya! Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.