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 8812225
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:33:27+00:00 2026-06-14T03:33:27+00:00

I’m getting my data ,with several similar methods, from sqlite3 file like in following

  • 0

I’m getting my data ,with several similar methods, from sqlite3 file like in following code:

-(NSMutableArray *) getCountersByID:(NSString *) championID{

    NSMutableArray *arrayOfCounters;
    arrayOfCounters = [[NSMutableArray alloc] init];

    @try {
        NSFileManager *fileManager = [NSFileManager defaultManager];
        NSString *databasePath = [[[NSBundle mainBundle] resourcePath ]stringByAppendingPathComponent:@"DatabaseCounters.sqlite"];
        BOOL success = [fileManager fileExistsAtPath:databasePath];

        if (!success) {
            NSLog(@"cannot connect to Database! at filepath %@",databasePath);
        }
        else{
            NSLog (@"SUCCESS getCountersByID!!");
        }
        if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK){

            NSString *tempString = [NSString stringWithFormat:@"SELECT COUNTER_ID FROM COUNTERS WHERE CHAMPION_ID = %@",championID];
            const char *sql = [tempString cStringUsingEncoding:NSASCIIStringEncoding];
            sqlite3_stmt *sqlStatement;

            int ret = sqlite3_prepare(database, sql, -1, &sqlStatement, NULL);

            if (ret != SQLITE_OK) {
                NSLog(@"Error calling sqlite3_prepare: %d", ret);
            }
            if(sqlite3_prepare_v2(database, sql, -1, &sqlStatement, NULL) == SQLITE_OK){

                while (sqlite3_step(sqlStatement)==SQLITE_ROW) {
                    counterList *CounterList = [[counterList alloc]init];
                    CounterList.counterID = [NSString stringWithUTF8String:(char *) sqlite3_column_text(sqlStatement,0)];
                    [arrayOfCounters addObject:CounterList];
                }
            }
            else{
                NSLog(@"problem with database prepare");
            }
            sqlite3_finalize(sqlStatement);
        }
        else{
            NSLog(@"problem with database openning %s",sqlite3_errmsg(database));
        }   
    }
    @catch (NSException *exception){
        NSLog(@"An exception occured: %@", [exception reason]);
    }
    @finally{
        sqlite3_close(database);
        return arrayOfCounters;
    }
    //end
}

then i’m getting access to data with this and other similar lines of code:

myCounterList *MyCounterList = [[myCounterList alloc] init];
countersTempArray = [MyCounterList getCountersByID:"2"];

[countersArray addObject:[NSString stringWithFormat:@"%@",(((counterList *) [countersTempArray objectAtIndex:i]).counterID)]];

I’m getting a lot of data like image name and showing combination of them that depends on users input with such code:

UIImage *tempImage = [UIImage imageNamed:[NSString stringWithFormat:@"%@_0.jpg",[countersArray objectAtIndex:0]]];

[championSelection setBackgroundImage:tempImage forState:UIControlStateNormal];

My problem:

When i’m run my app for some time and get a lot of data it throws error: ” problem with database openning unable to open database file – error = 24 (Too many open files)“

My guess is that i’m opening my database every time when getCountersByID is called but not closing it.

My question:

Am i using right approach to open and close database that i use?


Similar questions that did not helped me to solve this problem:

  1. unable to open database
  2. Sqlite Opening Error : Unable to open database

UPDATE:

I made assumption that error is showing up because i use this lines of code too much:

NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *databasePath = [[[NSBundle mainBundle] resourcePath ]stringByAppendingPathComponent:@"DatabaseCounters.sqlite"];
BOOL success = [fileManager fileExistsAtPath:databasePath];

and ending up with error 24.

So i made them global but sqlite3_errmsg shows same err 24, but app runs much faster now

  • 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-14T03:33:28+00:00Added an answer on June 14, 2026 at 3:33 am

    You should open your DB only once basically when you are in the initialization phase but not when you are requesting some info to your DB. Your code shouldn’t failed though since you seems to open then close the DB after each request. Make sure this is happening by either logging those events or debugging through your code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to render a haml file in a javascript response like so:
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I've got a string that has curly quotes in it. I'd like to replace
I have this code to decode numeric html entities to the UTF8 equivalent character.

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.