PRB: ODBC Database Remains Open After a Close Method Used (110227)
The information in this article applies to:
- Microsoft Visual Basic Standard Edition for Windows 3.0
- Microsoft Visual Basic Professional Edition for Windows 3.0
This article was previously published under Q110227 SYMPTOMS
Using a Close method on a database opened with Open Database Connectivity
(ODBC) drivers doesn't close the database. The ODBC database process keeps
running. To close the connection successfully, you must end the Visual
Basic application.
CAUSE
After Visual Basic executes the Close method on an ODBC connection, the
Microsoft Access engine in Visual Basic maintains a persistent connection
in case the user reopens the database later in the program. This makes the
program more efficient.
RESOLUTION
If a Visual Basic program does not reopen the ODBC connection after doing a
Close method, a time-out occurs and the connection closes automatically.
You can control the time-out period by placing the following line in your
VB.INI or <vb_exe_app_name>.INI file, where x is the number of seconds:
[ODBC]
ConnectionTimeout=x
The default ConnectionTimeout is usually 600 seconds (10 minutes). The
lowest supported ConnectionTimeout value is 1 second. A ConnectionTimeout
value of 0 says to never cause a time-out.
To enforce the fastest possible time-out, you can set ConnectionTimeout
to 1. In addition, you can add the following code after you close the
database to make sure the connection is terminated:
db.Close ' Close database, using database object variable (db).
Start = Timer
Do ' This loop pauses a second to allow a time-out
FreeLocks ' Tell Microsoft Access engine that program is idle.
DoEvents ' Tell Windows to do any pending events.
Loop While Timer <= Start + 1
This loop delays for a second after the db.Close. The FreeLocks statement
tells the database engine that the user is idle. If you run the Visual
Basic program with ConnectionTimeout set to 1 in your VB.INI or
<vb_exe_app_name>.INI file, the database engine will disconnect the
one-second-old connection to the server.
STATUS
This behavior is by design for all ODBC database connections.
REFERENCES
"Microsoft Visual Basic for Windows Professional Features Book 2:
Data Access Guide," pages 149-154 in Appendix C.
Modification Type: | Major | Last Reviewed: | 10/29/2003 |
---|
Keywords: | kbinterop kbprb KB110227 |
---|
|