My app connects each time I use the database. This strategy has worked well for me. Honestly, I prefer this method because temporary problems with the network may not affect you.
If you plan on doing this and you are using a SQL Server database, then you will want to make sure the database is not set to AutoClose. Basically, databases can be opened or closed. When a database is open, SQL Server will retain data in it's cache. The first time you request data from a table, it needs to go to the hard drive to get it. SQL Server will keep this data in memory so that subsequent requests will operate faster.
When the database is configured for autoclose, SQL Server will remove all the cached data from memory as soon as the last connection to that particular database is closed. When you are creating a connection every time you use the database, it ends up getting closed a lot.
What's worse.... When you use SQL Express and create a new database, the default setting is for AutoClose to be on. This kinda makes sense when you think about how Microsoft expects this database engine to be used. But... it really kills performance, too.
To see if your Microsoft SQL Server database is set to auto close:
Code:
Select 'Database set to Auto Close' As Problems
Where DatabaseProperty(db_name(), 'IsAutoClose') = 1
Make sure you run that in a query window and that the database is set properly.
-
George
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom