How to fix "The handle is invalid. (Exception from HRESULT: 0x80070006 (E_HANDLE))"


Today, one of the websites that I developed started throwing an error message saying:


Server Error in '/' Application.

The handle is invalid. (Exception from HRESULT: 0x80070006 (E_HANDLE))

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Runtime.InteropServices.COMException: The handle is invalid. (Exception from HRESULT: 0x80070006 (E_HANDLE))

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[COMException (0x80070006): The handle is invalid. (Exception from HRESULT: 0x80070006 (E_HANDLE))]   System.Transactions.Transaction.JitSafeGetContextTransaction(ContextData contextData) +0   System.Transactions.Transaction.FastGetTransaction(TransactionScope currentScope, ContextData contextData, Transaction& contextTransaction) +169   System.Transactions.Transaction.get_Current() +121   System.Data.ProviderBase.DbConnectionPool.GetFromTransactedPool(Transaction& transaction) +15   System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) +147   System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +108   System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +126   System.Data.SqlClient.SqlConnection.Open() +125   System.Data.EntityClient.EntityConnection.OpenStoreConnectionIf(Boolean openCondition, DbConnection storeConnectionToOpen, DbConnection originalConnection, String exceptionCode, String attemptedOperation, Boolean& closeStoreConnectionOnFailure) +52



Solution:

This kind of error usually comes when the COM object your InterOp is accessing is throwing an exception.  It is quite hard to give a straight forward answer without knowing that which COM your InterOp is calling.

So, there are 2 possible solutions that will fix this problem:


1st Solution) Under you IIS > Virtual Directory Properties > Execution Permissions might be marked as “Scripts and Executables” the dll is not being loaded so you are  getting “System.Runtime.InteropServices.COMException”

Try changing the Execution Permissions to “Scripts Only” and applying it - It should work now!

I am not sure about the exact different between the two so all I know is:

Scripts only  -> Run only scripts,such as ASP applications  and
Scripts and Executables -> Run both scripts, such as ASP applications, and executables



2nd Solution) On your server where you're website sits, open the command prompt and run the following command:

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis.exe -i - It should work now!

I hope it helps someone...

About Author

Written By Lavish Kumar

Based out of New York, USA, Lavish Kumar is a full stack web developer by profession and founder of Striving Programmers, a trusted community for developers that offers a wealth of articles and forums to assist individuals with improving their software development skills.

Related Blog Posts
Leave your comment
Comments
3/27/2014 9:15 PM
Thank you bro this solutuon work on my pc
3/27/2014 9:15 PM
Thank you bro this solutuon work on my pc
3/27/2014 11:09 PM
You're welcome :)
3/27/2014 11:09 PM
You're welcome :)
5/1/2014 3:42 AM
Thank you
5/1/2014 3:42 AM
Thank you
5/2/2014 2:53 PM
You're welcome Steven :)
5/2/2014 2:53 PM
You're welcome Steven :)
6/8/2016 7:32 PM
I have tried all the solutions as shared above but not worked for me, please share best solution for it.
6/8/2016 7:32 PM
I have tried all the solutions as shared above but not worked for me, please share best solution for it.