×

Discussion Board

Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    1

    Creating and Delete databases

    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.

    {
    RDbStoreDatabase* DbStore = NULL;
    RDbTable* DbTable = NULL;

    CEikonEnv* eikonEnv = CEikonEnv::Static();
    RFs fsSession = eikonEnv->FsSession();

    CFileStore* store = NULL;
    TInt leaveCode = 0;

    // Create database

    // Create a table definition
    CDbColSet* columns = CDbColSet::NewL();

    // add the columns
    TDbCol key(_L("Key&quot, EDbColUint32);
    key.iAttributes = TDbCol::EAutoIncrement;
    columns->AddL(key);

    // Attempt to create a new database
    TRAP(leaveCode,store = CPermanentFileStore::ReplaceL(fsSession, _L("C:\\test.dat&quot, 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&quot, *columns);

    // create the index key
    CDbKey* indexKey = CDbKey::NewL();

    // add the key columns
    TDbKeyCol keyCol(_L("Key&quot);
    indexKey->AddL(keyCol);

    // create the index
    DbStore->CreateIndex(_L("Info&quot, _L("Info&quot, *indexKey);

    delete indexKey;
    delete columns;

    DbTable = new RDbTable;
    DbTable->Open(*DbStore, _L("Info&quot, 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&quot);
    }

  2. #2
    Registered User
    Join Date
    Mar 2003
    Posts
    4

    RE: Creating and Delete databases

    Wait...

    ISTR that the DBMS server hangs around with the DB open for a second or two after the last access. See if a five second delay solves your problem.

    N.b. This is a suggestion only... :-)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×