|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Open SQL Connections
Hi,
I am a newbie, how can I check that all my connections get closed, as I go through the app? also, as for efficiency, is it better to hard code things in, or take them from a db? for example, i have multiple states drop down list. I can either hard code the array in, and reference it all over the place, or i can make a db table. which is more efficient? thanks in advance! |
|
#2
|
||||
|
||||
|
If you use a Using declaration on your connection, .NET automatically closes it when it reaches the end Using call.
In VB Code:
Dim conn as new Connection.... Using Conn End Using C# Code:
connection conn = new Connection...
using (conn)
{
}
I still tend to include calls to Close() methods and have using as a fail safe to catch any I miss. Bit of overkill maybe... ![]() In terms of efficiency, if you think about it in terms of getting the information you want in the least number of hops. So, a call to a database will always be less efficient as it's another hop to getting the data you need. It's more a case of ascertaining what functionality you need. If it's a simple yes/no dropdown, then hard code it. If it's likely to change / update regularly then use a database. If using a database, it may be more efficient is to pass the values into cache on Application Start and then access them from there each time you need them. Then if they get updated, make sure you call a method to update the cached version. All depends how often the values will be needed, how much memory would they take up etc. It's a matter of measuring how much resource would be used against the increased efficiency of getting the data from memory rather than the db each time. Hope that helps.
__________________
Policy Check I'd rather have a full bottle in front of me, than a full frontal lobotomy...
|
![]() |
| Viewing: ASP Free Forums > Programming > .NET Development > Open SQL Connections |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|