0X8004E007

CONTEXT_E_OLDREF 0X8004E007 Fix for COM+ Database

This error pops up when a COM+ app tries to use stale transaction context after a database failover. The fix: reset the COM+ application and clear old transaction references.

You're running a legacy line-of-business app that talks to SQL Server through COM+. Everything's been fine for months. Then one afternoon, the database server fails over to its replica—maybe a network blip, maybe a patch reboot. Suddenly your app throws CONTEXT_E_OLDREF (0X8004E007) on every new transaction. Users see it as a generic error, but the event log shows the COM+ component can't get a fresh transaction context.

The root cause is simple: COM+ caches a reference to the transaction context object. When the database connection drops mid-transaction, that reference goes stale. The next call tries to use the old context, and COM+ refuses because the transaction is no longer valid. It's like having a phone number saved for someone who just moved—you dial, but you get a dead line.

The fix is to force COM+ to release that stale reference and start clean. You don't need to reboot the server (unless you want to, but that's overkill). You just need to reset the COM+ application that hosts your component. Here's how to do it on Windows Server 2016 or 2019.

  1. Open the Component Services snap-in. Press Win + R, type dcomcnfg, and hit Enter. You'll see the Component Services tree.
  2. Expand Component Services > Computers > My Computer > COM+ Applications. You'll see a list of applications. Find the one that matches your component—usually named after your app, like "MyAppServer".
  3. Right-click that application and select Shut down. This stops all running components in that app. You should see the application icon change to a stopped state. If it's already stopped, skip this step.
  4. Right-click the same application and select Start. This restarts the COM+ app and forces it to create fresh transaction context objects. Wait a few seconds—the icon should go back to normal.
  5. Now test your app again. Try a simple transaction that previously failed. If the error is gone, you're done. If not, continue to the next step.

Sometimes shutting down the app isn't enough because the old reference sits in the Microsoft Distributed Transaction Coordinator (MSDTC) cache. You might need to restart that service too. Here's how:

  1. Open an elevated Command Prompt (right-click and select Run as administrator).
  2. Type net stop msdtc and press Enter. The service will stop. Wait a few seconds.
  3. Then type net start msdtc and press Enter. This restarts MSDTC and clears any lingering transaction state.
  4. Go back to Component Services and start the COM+ application again if it stopped (right-click > Start).
  5. Test your transaction again. This usually does the trick.

If you're still hitting 0x8004E007 after these steps, you need to look at your connection pooling. COM+ components often pool database connections, and if the pool holds a connection to the old database server, you'll keep getting stale contexts. The real fix is to clear that pool.

Here's a quick way to clear it without restarting the app:

sqlcmd -S your_database_server -E -Q "DBCC FREEPROCCACHE"

That clears the procedure cache on the SQL Server side, which forces new connections to be created. But if your component uses a specific connection string, you might need to update it to point to the new server if the failover changed the IP or hostname. Check your application's config file (like web.config or an XML config in the COM+ package) for the database server name.

Also, consider bumping up the transaction timeout. If your database failover takes longer than the default 60 seconds, COM+ will give up and mark the context as stale. You can increase it in the COM+ application properties:

  1. Right-click your COM+ application and select Properties.
  2. Go to the Transactions tab.
  3. Under Transaction Timeout, set it to a higher value, like 120 seconds. Click OK.
  4. Shut down and restart the application again to apply the change.

After you've done all this, the error should be gone. But here's the thing: this will happen again after the next failover. So plan ahead. Set up a scheduled task that runs at 3 AM and resets the COM+ app. Or better, update your code to handle the stale context gracefully—catch the CONTEXT_E_OLDREF HRESULT and retry the transaction once. That's the real long-term fix.

If you try everything and still see the error, check the Windows Event Log under Applications and Services Logs > Microsoft > Windows > COM+. Look for event ID 4096 or similar—it might point to a specific component that's not releasing references properly. Sometimes the issue is a bug in the component itself, and you'll need to contact the vendor for a patch.

One last thought: don't ignore this error. It's not just a nuisance. It can cause silent data corruption if you don't restart the transaction properly. So when you see it, stop what you're doing and reset the COM+ app—every time.

Related Errors in Database Errors
0X8004D01B XACT_E_TMNOTAVAILABLE Fix: Transaction Manager Not Available 1118 Fix MySQL ERROR 1118: Row size too large (InnoDB) 0X0000028F Fixing ERROR_VOLSNAP_PREPARE_HIBERNATE (0x0000028F) HTTP 406 / SQL Injection Blocked SQL Injection Attempt Blocked – 3 Causes and Fixes

Was this solution helpful?

EP
Erropedia Team
Tech Support Editors
The Erropedia editorial team researches and documents real-world tech errors from across Windows, Linux, macOS, networking, databases, cloud platforms, and more. Every solution is reviewed for accuracy and updated as software and systems evolve.