Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8140839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T12:17:51+00:00 2026-06-06T12:17:51+00:00

I get unable to open database file when executing rc = sqlite3_open(test.db, &db); ??

  • 0

I get “unable to open database file” when executing rc = sqlite3_open(“test.db”, &db); ??

sqlite3 *db; // sqlite3 db struct
char *zErrMsg = 0;
int rc;

// Open the test.db file
rc = sqlite3_open("test.db", &db); // <-- creates DB if not found ??

if( rc ){
    // failed
    fprintf(stderr, "ERROR: Can't open database: %s\n", sqlite3_errmsg(db));
} 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T12:17:52+00:00Added an answer on June 6, 2026 at 12:17 pm

    sqlite3_open returns an error if the database does not already exist. To create the database if it doesn’t already exist, use sqlite3_open_v2 with the SQLITE_OPEN_CREATE and SQLITE_OPEN_READWRITE flags (both are required):

    rc = sqlite3_open_v2(/* DB Path */, &db, SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE, NULL);
    

    Reference


    To find /* DB PATH */, you need to base the filename off of the documents directory:

    - (NSString *) applicationDocumentsDirectory 
    {    
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *basePath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;
        return basePath;
    }
    

    You can use this convenience method to combine the documents path with the database name:

    NSString *documents = [self applicationDocumentsDirectory];
    NSString *dbPath = [documents stringByAppendingPathComponent:@"test.db"];
    
    rc = sqlite3_open_v2([dbPath UTF8String], &db, SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE, NULL);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I renamed the class classBattle to Game and not I get Unable to load
I am unable to get the correct title for this, please change the title
I am unable to get a highcharts plugin to render a chart in a
I'm unable to get this jquery statement to work on page load but it
I'm unable to get the Central Maven repo index. I'm running Netbeans 7.0.1 and
I am unable to get a Javascript callback to work with gmaps4_rails when the
I'm unable to get the length of the following JSON array object. Actually I
Why do I get the error: Unable to create a constant value of type
I have the following code and I am still unable to get Hibernate to
I'm trying to insert data into my SQlite3 database (this works via the command

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.