Today I got this error while I was coding a cms panel. I’ve researched for solution but there was nothing to do with most of them. Then I’ve looked up my code and I’ve realized that I haven’t closed my reader. After I added rdr.Close(); to my code block before closing using statement, problem was solved.

Also you can add rdr.Dispose(); In my code I delete previous uploaded files and sometimes it gives error when the file that needs to be deleted is already deleted. And this is the reason why command cannot be closed. So close and dispose the reader. Problemo solved :)

Error:
COM object that has been separated from its underlying RCW cannot be used.

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.InvalidComObjectException: COM object that has been separated from its underlying RCW cannot be used.

Stack Trace:

[InvalidComObjectException: COM object that has been separated from its underlying RCW cannot be used.]
   System.Data.Common.IAccessor.ReleaseAccessor(IntPtr hAccessor, Int32& pcRefCount) +0
   System.Data.OleDb.RowBinding.Dispose() +86
   System.Data.OleDb.Bindings.Dispose() +30
   System.Data.OleDb.OleDbCommand.CloseInternalParameters() +18
   System.Data.OleDb.OleDbCommand.ResetConnection() +23
   System.Data.OleDb.OleDbCommand.Dispose(Boolean disposing) +27
   System.ComponentModel.Component.Dispose() +17
   Admin_addContent.LoadCategory() in z:\siteRoot\*.com\Admin\addContent.aspx.cs:223
   Admin_addContent.Page_Load(Object sender, EventArgs e) in z:\siteRoot\*.com\Admin\addContent.aspx.cs:29
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
   System.Web.UI.Control.OnLoad(EventArgs e) +99
   System.Web.UI.Control.LoadRecursive() +50
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627