0

I am trying to connect to an SQL Database with FMDB that is on my development machine desktop. I can open it from sqlite3 from a terminal and it has the data in it.

When I try and use this code from Cocoa I get an "error opening!: 14"

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDesktopDirectory, NSUserDomainMask, YES);
NSString *docsPath = [paths objectAtIndex:0];
NSString *path = [docsPath stringByAppendingPathComponent:@"database.sqlite"];
FMDatabase *database = [FMDatabase databaseWithPath:path];     

What do I need to do to solve this and where is the preferred place to store data?

Edward Hasted
  • 3,201
  • 8
  • 30
  • 48

1 Answers1

0

Try to add

NSLog(@"Path: %@",path);,

then go to the path the console will give you and try to see if you can open the file.

The preferred place to store data is Documents folder. But first you have to load it from bundle, then copy it to Documents in order to allow writing \ editing.

Phillip
  • 4,276
  • 7
  • 42
  • 74
  • Good thinking - the path the simulator returns is: /Users/EdwardHasted/Library/Application Support/iPhone Simulator/5.1/Applications/3AC34CE6-D05F-4568-BC94-DBA1DC23E445/Desktop/database.sqlite What I don't understand is why the simulator doesn't simulate the Desktop environment, what I need to do to make the Simulator work and what I need to do for location with the live example? Excuse current naivety. – Edward Hasted Jul 03 '12 at 06:51
  • Well open the location from Terminal and check if it opens fine. What are you doing, though? – Phillip Jul 03 '12 at 08:54
  • Look at the original posting, it opens fine in terminal mode on the development machine. Can I open terminal mode on the simulator - that's where the problem is in that the file locations are different. – Edward Hasted Jul 03 '12 at 19:12