Unable to close IDatabase

I’ve found out a littlbe bit more about this… It appears that I also can’t close any databases at all…

IDatabaseListPtr pDBList;
IDatabasePtr toRemove;
pDBService->GetOpenDatabases(&pDBList);

OutputDebugString(L"\n");
OutputDebugStringA(stringify(pDBList->GetCount()).c_str());
OutputDebugString(L" databases open initially.");

while (pDBList->GetCount() > 0)	
{
	if( (iRet=pDBList->GetDatabase(0, &toRemove)) != kServiceNoErr )
	{
		OutputDebugString(L"Error getting from list!");
	}
	if( (iRet=toRemove->Close()) != kServiceNoErr)
	{
		OutputDebugString(L"Error closing database!");
	}
	if( (iRet=pDBList->RemoveDatabase(toRemove)) != kServiceNoErr )
	{
		OutputDebugString(L"Error removing database!");
	}
}

pDBService->GetOpenDatabases(&pDBList);
OutputDebugString(L"\n");
OutputDebugStringA(stringify(pDBList->GetCount()).c_str());
OutputDebugString(L" databases open after closing them all.");

Before this bit of code is run, I open EndNote. Then, I open 1 database. After that, I execute this code, which gives the following results:

2 databases open initially.

2 databases open after closing them all.

edit: I just realized something… If I open the Database from within EndNote, then my plugin is not the owner, and I cannot close it this way.