Which use of connection management is better while developing a windows based application which uses a Database as its data store? What about web-based applications?
- when user loads the first form of an application, the global
connection opens and on closing the last form of the application
the connection closes and disposes. - for each form within the application, there is a local connection
(form scope) and when user wants to perform an operation like
insert, update, delete, search, … the application uses the
connection and by unloading the form the connection also closes and
disposes. - for every operation within a form of an application, there is a
local connection (procedure scope) and when user wants to perform
an operation like insert, update, delete, search, … the
application uses procedure connection and at the end of every
procedure within the form, the connection also closes and disposes.
Go with #3
You should try to only ever keep connections open for just as long as is required.
Also have a look at
(ADO.NET)