Error opening a db file over my ipod

Discussion in 'iOS Programming' started by skunkio, May 31, 2010.

  1. skunkio macrumors newbie

    Apr 25, 2010
    Hi all,
    i'm testing for the first time my app on my touch...i'm so excited!!! :D

    Anyway, something is not working properly and i receive an error when my app tries to open a db file.
    Inside my code i check if a db file exsists within my app folder.
    Using the row below i create the path file i suppose to be used by my app

    DB_NAME = [[NSString alloc] initWithFormat:@"%@/%@", NSHomeDirectory(), @"test.db"];
    and this is the result:


    then with a simple cicle i check if this file exists in my app folder (always in NSHomeDirectory()).
    If it's not there i run some sql to set my db properly. I use code below to open a connecion

    const char *dbName = [database UTF8String];
    dbrc = sqlite3_open(dbName, &db);
    if (dbrc) {
            NSLog (@"couldn't open db: %@ (error number: %i)", database, dbrc);		
    	return FALSE;
    and i receive the following error

    couldn't open db: /var/mobile/Applications/5DCA12D5-7FD4-4643-A63A-D60A0193DFE4/test.db (error number: 14)

    Infact error number is clear, from sqlite result codes

    #define SQLITE_CANTOPEN 14 /* Unable to open the database file */

    Can i create e file in this folder?


    Moreover, i see the long name after Applications changing every time i switch on my ipod and run my app.
    Where i should save my db file over my iPod and be sure to use the same path when i switch on my ipod again?

  2. skunkio thread starter macrumors newbie

    Apr 25, 2010
    Solved the issue, seems i can't write directly in my app root folder but i can in the Documents folder.
    I changed my code creating my db file there and now it works (i changed also the way to identify my app folder but this is not the main problem).

  3. PhoneyDeveloper macrumors 68040


    Sep 2, 2008
    Don't use stringWithFormat to build paths. Use stringByAppendingPathComponent and related methods.

Share This Page