I am creating database in my app,after creating the Db,i am trying to copy the db from the app bundle to Doc directory.But i could not copy it,i am getting error like
The operation couldn’t be completed. (Cocoa error 260.)
Below shown is the code what i am using,please help me to fix this issue
dbName="userDetails.db";
returnCode=sqlite3_open(dbName,&handler);
if(returnCode!=SQLITE_OK)
NSLog(@"message---%s",sqlite3_errmsg(handler));
else
NSLog(@"sucess---%d",returnCode);
NSFileManager *fmgr=[NSFileManager defaultManager];
NSError *error;
NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
NSString *path=[paths objectAtIndex:0];
NSString *docPath=[path stringByAppendingPathComponent:@"userDetails.db"];
if(![fmgr fileExistsAtPath:docPath]){
NSString *defaultDBPath=[[[NSBundle mainBundle]resourcePath]stringByAppendingPathComponent:@"userDetails.db"];
if(![fmgr copyItemAtPath:defaultDBPath toPath:docPath error:&error])
NSLog(@"failure message----%@",[error localizedDescription]);
}
Actually I am little confuse with your code. Are you trying to programmatically create a database in the app bundle and then copying it to documents directory? If this is what you are doing then you need to know that you can’t create or modify anything in app bundle. You must create this database in Documents directory. You should do something like this –
But if you already have a database in your app (and not dynamically creating) and you just want to copy it to documents directory then you should follow @Santosh Gurram answer.