简体   繁体   中英

how to solve run time error 'Failed to create writable database file with message 'The operation couldn’t be completed. (Cocoa error 260.)'.'?

I am beginner of iPhone I have created database but that give run time error of Failed to create writable database file with message 'The operation couldn't be completed

my code is

-(void)createdatabase
{
    NSFileManager *fileManager=[NSFileManager defaultManager];
    NSError *error;
    NSString *dbPath=[self getDBPath];
    BOOL success=[fileManager fileExistsAtPath:dbPath];
    if(!success)
    {
        NSString *defaultDBPath=[[[NSBundle mainBundle]resourcePath] stringByAppendingPathComponent:@"SQL.sqlite"];
        success=[fileManager copyItemAtPath:defaultDBPath toPath:dbPath error:&error];
        if(!success)
        {
                NSAssert1(0, @"Failed to create writable database file with message '%@'.", [error localizedDescription]);  
        }

    }
}

give any suggestion and source code which is apply in my code

I have done little google for this error code and I found that

NSFileReadNoSuchFileError = 260,                        // Read error (no such file)

So, please make sure that DB file(SQL.sqlite) is there on path by which you are referring in your above snippet.

试试这个:从模拟器的应用程序文件夹中删除应用程序,然后再次运行应用程序。我刚做完这个小工作,我的错误就是..祝你好运..

If Shah Paneri's answer does not work for you you can additionally look at your database file's "Target Membership". Be sure that your project is selected. If it is not (as mine was not), selecting this should fix the problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM