I've recently had a problem with my site displaying a "system resources exceeded" error message ... and whilst searching this site for a solution (which I think I've now found) I came across mention of closing database connections and so had a "best practice" question which I hoped someone might be able to help me with?
I'm a .asp newbie and much of what I have learnt has been done by looking at various snippets of code on the web and "hacking and slashing" code to get it to do what I need..... so needless to say, I've probably (inadvertently) picked up some bad habits.
However, I want to improve my coding and so I thought I'd start with connections sooo.....
Question 1: Opening Connections
Is there a best way to open a database connection? I've seen some people use a DNS.....
set objconn = Server.CreateObject("ADODB.Connection")....and others use an absolute path.
objconn.open "DSN=mydatabase;","addon","addons69%"
Dim connAlso, how do you reference a usename and password with each approach?
'create a database connection
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=c:\pathtomy_database.mdb;" & _
"Jet OLEDB:Database"
Is either better or more secure than the other, or are there situations where one should be used over the other, or is it just a question of personal preference?
Question 2: Closing connections.
I've seen mention that you should close connections with something like:
obj.close... but what I wondered is whether you should also close:
obj = nothing
a) recordsets?
b) variables?
If you should close these, then can you do it just by closing the connection (i.e. does closing the connection mean that all child dependents collapse by default?)
Finally, do the following each need to be closed?
- Set domDoc = server.CreateObject("MSXML.DOMDocument")
- Filename = server.MapPath("filename.xml")
Thanks
Kessa