Ending database connections

darkmastergyz

Registered User.
Local time
Today, 13:55
Joined
May 7, 2006
Messages
85
I heard for good database practices, whenever you're done with opening and using a database, you should close the connection. So if I have an example connection like this, are the statements at the end enough?

dim db as database
dim rs as recordset
set db = current db
dim strSQL as string
strSQL = "SELECT * FROM db"
set rs = db.openrecordset(strSQL, openDynaSet)

(END):
set rs = nothing
rs.close
set db = nothing
db.close
 
I heard for good database practices, whenever you're done with opening and using a database, you should close the connection. So if I have an example connection like this, are the statements at the end enough?

dim db as database
dim rs as recordset
set db = current db
dim strSQL as string
strSQL = "SELECT * FROM db"
set rs = db.openrecordset(strSQL, openDynaSet)

(END):
set rs = nothing
rs.close
set db = nothing
db.close

The "end" statements are backwards, the close needs to come before you set the object to nothing otherwise you will get an error.

Should be:

Code:
(END):
rs.close
set rs = nothing
db.close
set db = nothing
 
But those are it, right?
 
Yes, in fact I've read that you really only need one or the other, so I usually just set to nothing.
 
I have heard that the .close makessure that any changes are written back to the file. Setting the rs to nothing frees up any dynamic resources used in Access.
 
I have heard that the .close makessure that any changes are written back to the file.

That is not correct. According to Help, changes will be lost if the recordset is closed before .Update is executed.
 

Users who are viewing this thread

Back
Top Bottom