I have a function which should create a database, perform some actions, and possibly delete the database when done. When I attempt to delete the database, I get an error code of -14, KErrInUse.
To demonstrate the problem, I have a sample function which will create a database and then delete the database.
Any insight into why this file is considered in use will be helpful.
// Attempt to create a new database
TRAP(leaveCode,store = CPermanentFileStore::ReplaceL(fsSession, _L("C:\\test.dat", EFileRead | EFileWrite));
if (leaveCode)
{
store = NULL; // ensure that store is NULL on failure
}
if (!store)
{
// Failed to create file
return;
}
// Complete file store creation
store->SetTypeL(store->Layout());
// Create a database in the store
DbStore = new RDbStoreDatabase;
TStreamId id = 0;
TRAP(leaveCode,id = DbStore->CreateL(store));
if (leaveCode)
{
return;
}
// Keep database id as root of store
store->SetRootL(id);
// Complete database creation by commiting the store
store->CommitL();
// Create a table
DbStore->CreateTable(_L("Info", *columns);
// create the index key
CDbKey* indexKey = CDbKey::NewL();
// add the key columns
TDbKeyCol keyCol(_L("Key");
indexKey->AddL(keyCol);
// create the index
DbStore->CreateIndex(_L("Info", _L("Info", *indexKey);
delete indexKey;
delete columns;
DbTable = new RDbTable;
DbTable->Open(*DbStore, _L("Info", RDbRowSet::EUpdatable);
// Close the existing tables & databases
if (DbTable)
{
DbTable->Close();
delete DbTable;
DbTable = NULL;
}
if (DbStore)
{
DbStore->Close();
delete DbStore;
DbStore = NULL;
}
// Delete the databases
TInt errorCode;
errorCode = fsSession.Delete(_L("C:\\test.dat");
}