Ketan Shinde
Ketan Shinde

Reputation: 1847

Database connection, checking database path

i have created database in sqlite manager. my project get terminated due to exception. when i took the help of break point then i get the "bad access" at line 3rd. I am unable to get the solution for the problem at 3rd line.

-(void)checkAndCreateDB
{
    BOOL Success;
    //NSFileManager maintains file
    NSFileManager *FileManager = [NSFileManager defaultManager];
    //Checks Database Path
    Success = [FileManager fileExistsAtPath:dbpath];
    //If file exists it return true
    if(Success)return;
    NSString *databasePathFromApp = [[[NSBundle mainBundle]resourcePath]stringByAppendingPathComponent:dbname];
[FileManager copyItemAtPath:databasePathFromApp toPath:dbpath error:nil];
    [FileManager release];
}

Here dbpath=

/Users/gauravmurghai/Library/Application Support/iPhone Simulator/User/Applications/E48F72FD-5CC9-438C-B412-7D16FEF8DD8C/Documents/dbnitu.sqlite

Error is displayed at line 3:“EXC_BAD_ACCESS”.

line 3 is: Success = [FileManager fileExistsAtPath:dbpath]; I cannot understand where the problem is?Unable to overcome this error.

Upvotes: 1

Views: 176

Answers (1)

visakh7
visakh7

Reputation: 26400

-(void)checkAndCreateDB
{

    //NSFileManager maintains file
    NSFileManager *FileManager = [NSFileManager defaultManager];
    //Checks Database Path
    if([FileManager fileExistsAtPath:dbpath]);
    //If file exists it return true
    return;
    NSString *databasePathFromApp = [[[NSBundle mainBundle]resourcePath]stringByAppendingPathComponent:dbname];
[FileManager copyItemAtPath:databasePathFromApp toPath:dbpath error:nil];
    [FileManager release];
}

Upvotes: 0

Related Questions