Unanswered: closing db connection in err handlers.
I have a database object that has a connect & a disconnect method which other objects can use.
In my database object (called databroker) my connect & disconnect looks like:
Function Connect () as boolean
set goConn = adodb.connection....
Function Disconnect() as boolean
set goConn = Nothing
Often times, I'll do things like:
Dim objDB as databroker
set objDB = new databroker
If objdb.Connect Then
What I'm wondering is when the code crashes (for whatever reason) before the disconnect is called, I try to disconnect again in the error handler. Will setting the global connection object to nothing "properly" close my database or should I actully be using goConn.Close ?? If the database didn't get opened and i try to call goConn.Close, will it work?
The connection object is just the means for your applicaiton to provide a connection to your datasource which specify the specific data provider and paramenters. It does not open your database.
The Recordset open/close as implies will do your tables and records.
In my experience, when the application crashed for one reason or another, the connection seems to stay active until I re-start the applcation. In Access database it's easy to determine because once the database is open it creates a record-locking file and disappear when the connection is closed.
It is safer I say that the tables be closed first to prevent corruption if your application does not have a roll back when it malfuncitons during data movements.
I guess i have the same question. Will the database close automatically if the connection closed? I'm sure that this mechanics is considered in the database system design. Or will it disconnect if the database is still open?
YOu have these sequence of events here.
first you make connection
second open the database
third close the database
fourth you disconnection or close the connection.
I guess you can add a verification on your error handler to verify that connection is closed after the variable is set to nothing
Further.. Your goConn is a variable you declared and assigned to an instance for the class connection, then you have to set it to nothing to vanish the instance when no longer desire to use.
so the question is. If the instance is set to nothing, will the connection parameter get disconected automatically and all the database tables automatically closed?
or Does the system allow the the connection instance to be set to nothing when database is currently connected and database is currently opened?