PRB: ODBC Database Remains Open After a Close Method UsedID: Q110227
|
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.
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.
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
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 behavior is by design for all ODBC database connections.
Section Value Effect
----------------------------------------------------------------
RmtTrace 0 Use asynchronous query execution
if possible; no ODBC API tracing
(default).
8 Trace ODBC API calls in ODBCAPI.TXT
in the Microsoft Access directory.
16 Force synchronous query execution.
24 Trace ODBC API calls; force
asynchronous query execution.
Section Value Effect
----------------------------------------------------------------
TraceSQLMode 0 No tracing of SQL queries (default).
1 Trace SQL queries sent to ODBC in
SQLOUT.TXT in the Microsoft Access
directory.
QueryTimeout S Wait S seconds for queries sent to
ODBC, and then stop trying to process
the query results (for asynchronous
queries only). (Default: 60 seconds).
LoginTimeout S Wait S seconds for ODBC login response,
and then stop trying to connect to a
server. (Default: 20 seconds).
ConnectionTimeout S Wait S seconds, and then close idle
ODBC connections. (Default: 600
seconds).
AsyncRetryInterval M Retry asynchronous queries every M
milliseconds. (Default: 500
milliseconds).
AttachCaseSensitive 0 Attach the first table whose name
matches the specified string,
regardless of case.
1 Attach a table only if its name
exactly matches the specified string.
AttachableObjects string A list of object types you can attach.
(Default: 'TABLE', 'VIEW', 'SYSTEM TABLE',
'ALIAS', 'SYNONYM'.)
SnapshotOnly 0 Get index information when tables are
attached so that dynasets are allowed
(default).
1 Ignore index information when tables
are attached so that only snapshots
are allowed.
"Microsoft Visual Basic for Windows Professional Features Book 2:
Data Access Guide," pages 149-154 in Appendix C.
Additional query words: jet caching
Keywords : kbinterop kbDatabase kbODBC
Version : 3.0
Platform : WINDOWS
Issue type : kbprb
Last Reviewed: June 8, 1999