Sitemap | EndNote
Showing results for 
Search instead for 
Do you mean 
Reply
Enthusiast
Posts: 21
Registered: ‎05-03-2011

Unable to close IDatabase

I have the follwoing code:

 

if( (pDBService = (IDatabaseService*)gCServiceRequest->GetService(kDatabase)) == NULL )
{
	throw CannotObtainServiceException();
}

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

// Create the new Database
if( (iRet=pDBService->Create(dbPath,modeDefault,&pLitCiterDB)) != kServiceNoErr )
{
	OutputDebugString(L"Error creating database!!!!!");
	throw ServiceException(iRet);
}

pLitCiterDB->Close();

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

 Before the call to create, there are no databases open. After the call to close, there is still 1 database open.

 

This later becomes troublesome when I try to open a library window in EndNote by doing:

if( (iRet=pUIService->OpenDatabase(dbPath)) != kServiceNoErr )

 This returns kServiceErrDbAlreadyOpen. 

 

 

What do I need to do to close this database?

 

 

--------------------------------------------------------------------------------------
This post does not necessarily reflect the views of my employer.

Nathan Ellenfield
ORISE Grantee- Immediate Office
National Center for Environmental Assessment
US Environmental Protection Agency
Research Triangle Park, NC 27711
Enthusiast
Posts: 21
Registered: ‎05-03-2011

Re: Unable to close IDatabase

[ Edited ]

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.

--------------------------------------------------------------------------------------
This post does not necessarily reflect the views of my employer.

Nathan Ellenfield
ORISE Grantee- Immediate Office
National Center for Environmental Assessment
US Environmental Protection Agency
Research Triangle Park, NC 27711
Moderator
Posts: 213
Registered: ‎03-28-2008

Re: Unable to close IDatabase

Reading over some notes on this I remembered that a plugin cannot close a database it did not open.  So if the user or another plugin opens a database your plugin cannot close the database.


Peter Travis

Thomson Reuters
Tel +1 800 336 4474
http://www.researchsoft.com
http://scientific.thomson.com

Better Decisions Faster
Thomson Reuters and its product names and acronyms used herein are trademarks, service marks, and registered trademarks used under license.
Enthusiast
Posts: 21
Registered: ‎05-03-2011

Re: Unable to close IDatabase

Yeah... I just realized that probably while you were writing that response... That applies to my example where I opened the library from within EndNote. However, in my original post, I Create it and then attempt to close it immediately within my plugin.

--------------------------------------------------------------------------------------
This post does not necessarily reflect the views of my employer.

Nathan Ellenfield
ORISE Grantee- Immediate Office
National Center for Environmental Assessment
US Environmental Protection Agency
Research Triangle Park, NC 27711
Enthusiast
Posts: 21
Registered: ‎05-03-2011

Re: Unable to close IDatabase

Now that I've fixed the threading issue from my other post, I still have problems when I try to create the database and then immediately close it.

--------------------------------------------------------------------------------------
This post does not necessarily reflect the views of my employer.

Nathan Ellenfield
ORISE Grantee- Immediate Office
National Center for Environmental Assessment
US Environmental Protection Agency
Research Triangle Park, NC 27711
Enthusiast
Posts: 21
Registered: ‎05-03-2011

Re: Unable to close IDatabase

I found a fix. I have to manually set all the references to NULL. (or make sure they run out of scope) It doesn't seem like Close() actually does anything when I call it. Even if pLitCiterDB is the last reference, calling pLitCiterDB->Close() doesn't close it.

--------------------------------------------------------------------------------------
This post does not necessarily reflect the views of my employer.

Nathan Ellenfield
ORISE Grantee- Immediate Office
National Center for Environmental Assessment
US Environmental Protection Agency
Research Triangle Park, NC 27711