遗留Access项目长期运行后频发Internal OLE Automation错误求助
Great question—this is a classic pain point with legacy Access + JDBC-ODBC setups that degrade over time. The fact that it starts with a single query and spreads suggests a gradual resource leak or database degradation, not just a one-time timeout. Let’s break down the most likely causes and actionable troubleshooting steps tailored to your environment (Java 6, Tomcat 6, Windows Server 2012, 32-bit Access driver):
1. First: Rule Out Connection/Resource Leaks (Most Common Culprit)
Long-running issues that spread over weeks almost always trace back to unclosed database resources. The JDBC-ODBC bridge is notoriously bad at cleaning up resources automatically, and Java 6 lacks try-with-resources to enforce this.
Audit your database code:
Go through every code block that interacts with the Access DB and verify thatConnection,Statement, andResultSetare all closed in afinallyblock—even if an exception is thrown. Example of correct cleanup:Connection conn = null; Statement stmt = null; ResultSet rs = null; try { conn = getConnection(); // Your connection retrieval logic stmt = conn.createStatement(); rs = stmt.executeQuery("SELECT ..."); // Process results } catch (SQLException e) { // Log/handle exception } finally { // Close resources in reverse order, suppress cleanup exceptions if (rs != null) try { rs.close(); } catch (SQLException ignored) {} if (stmt != null) try { stmt.close(); } catch (SQLException ignored) {} if (conn != null) try { conn.close(); } catch (SQLException ignored) {} }Missing even one
close()call can leave OLE resources hanging, which accumulates over weeks until the driver hits a limit.Monitor your connection pool (if using one):
If you’re using Tomcat’s built-in JDBC pool or another pooling library, enable JMX monitoring to track:- Active connection count (should not keep rising indefinitely)
- Idle connection count (should cycle as connections are reused/released)
A steadily increasing active connection count confirms leaks.
2. Check for Access Database Degradation
Access files bloat and fragment over time, which slows queries and strains the ODBC driver’s OLE resources.
Compact and Repair the Access DB:
This is a critical maintenance step for long-running Access databases. You can:- Manually open the DB in Access and run
Compact & Repair(do this during low traffic, with no active connections). - Automate it with a script using the Access command line:
Replace the Office path with your version (Office 2010 uses Office14, adjust as needed). Swap the compressed file back to the original path after completion."C:\Program Files (x86)\Microsoft Office\Office14\MSACCESS.EXE" "C:\path\to\your\database.mdb" /compact "C:\path\to\compressed_database.mdb"
- Manually open the DB in Access and run
Check for corrupted tables/indexes:
Run a simple query on each table to see if any throw errors, and verify that indexes are still valid. Corrupted indexes can cause queries to hang, leading to OLE timeouts/errors.
3. Troubleshoot Timeout-Related Issues
Your suspicion about timeouts is valid—slow queries can trigger OLE automation errors as the driver waits for resources.
Add query timeouts to your code:
Even if you don’t think queries are slow, adding a timeout ensures stuck queries don’t hang and leak resources. In Java 6, useStatement.setQueryTimeout():stmt.setQueryTimeout(30); // Time out after 30 secondsCheck ODBC driver timeout settings:
- Open the ODBC Data Source Administrator (32-bit, since your driver is 32-bit—run
C:\Windows\SysWOW64\odbcad32.exe). - Find your Access data source, go to
Configure > Advanced. - Verify that connection and query timeouts are set (not infinite). Adjust to a reasonable value (e.g., 30 seconds) if needed.
- Open the ODBC Data Source Administrator (32-bit, since your driver is 32-bit—run
Identify slow queries:
Enable query logging in your code to track how long each query takes. If you notice certain queries start taking longer over time, they may be the source of the initial error that spreads as resources are exhausted.
4. Investigate OLE Resource Exhaustion
The "Internal OLE Automation error" directly points to the ODBC driver running out of OLE-related system resources.
Monitor Tomcat’s system resources:
Open Task Manager, find the Tomcatjava.exeprocess, and track:- Handle count (should not keep rising without dropping)
- Thread count (excess threads can consume OLE resources)
- Private memory (steady growth indicates leaks)
If these metrics climb indefinitely over weeks, you have a resource leak that’s not related to database connections alone.
Check for COM object leaks:
The JDBC-ODBC bridge uses COM objects under the hood. In rare cases, complex queries (e.g., those involving OLE object fields, linked tables, or advanced functions) can leave COM objects unclosed. If you have such queries, test removing them temporarily to see if the error stops spreading.
5. Rule Out Driver/Environment Bugs
Your setup uses old software (Java 6, Tomcat 6) which has known limitations with the JDBC-ODBC bridge.
Check for Windows updates:
Install any pending Windows Server 2012 updates, especially those related to ODBC or OLE Automation. Microsoft occasionally patches driver bugs that cause resource leaks.Test with a newer Access driver (if possible):
While you’re stuck with the legacy setup, see if a newer 32-bit Access driver (e.g., from Office 2016/2019) fixes the issue. Note that you may need to install the Access Runtime if you don’t have Office installed on the server.
Final Notes
Start with connection leaks and database compact/repair—these are the fastest fixes for this specific error pattern. If those don’t resolve it, move on to resource monitoring and timeout adjustments.
内容的提问来源于stack exchange,提问作者Rodin10

