Hi Guys,
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.....
....and others use an absolute path.
Also, how do you reference a usename and password with each approach?
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:
... but what I wondered is whether you should also close:
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?
Thanks
Kessa
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.CreateOb ject("ADODB.Con nection")
objconn.open "DSN=mydatabase ;","addon","add ons69%"
objconn.open "DSN=mydatabase ;","addon","add ons69%"
....and others use an absolute path.
Dim conn
'create a database connection
Set conn = Server.CreateOb ject("ADODB.Con nection")
conn.Open "Provider=Micro soft.Jet.OLEDB. 4.0;" & _
"Data Source=c:\patht omy_database.md b;" & _
"Jet OLEDB:Database"
'create a database connection
Set conn = Server.CreateOb ject("ADODB.Con nection")
conn.Open "Provider=Micro soft.Jet.OLEDB. 4.0;" & _
"Data Source=c:\patht omy_database.md b;" & _
"Jet OLEDB:Database"
Also, how do you reference a usename and password with each approach?
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
obj = nothing
obj = nothing
... but what I wondered is whether you should also close:
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.CreateOb ject("MSXML.DOM Document")
- Filename = server.MapPath( "filename.x ml")
Thanks
Kessa
Comment