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

  • SEARCH
  • Home
  • 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 190891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T16:17:41+00:00 2026-05-11T16:17:41+00:00

I’m developing for iphone-sdk 2.2.1 (so no CoreData cry ). So I’m using the

  • 0

I’m developing for iphone-sdk 2.2.1 (so no CoreData cry).

So I’m using the FMDatabase project, which is just a SQLite Wrapper in Obj C. I have my DB working well when interacting with it from my AppDelegate. I’ve tested connecting, INSERTING, etc from the AppDelegate.

Now, I have a data object that I want to store into the Database. I would like this event to occur from a ViewController class. Lets see some code:

App Delegate Creates the DB in the applicationDidFinishLaunching method. The DB is declared as a property of this class so I can easily access it.

db = [FMDatabase databaseWithPath:[self getDBPath]];

This works fine, I have tested it. The only thing I’m a little concerned about is ‘db’ being a property of the class. That shouldn’t cause problems, should it?

From the same applicationDidFinishLaunching method, I’ve tested that a simple insert works using. This Works:

[db beginTransaction];
[db executeUpdate:@"INSERT INTO tblDataSamples (...) VALUES (...);"];
[db commit];

Now, if I simply take this exact code and move it to an instance method of the AppDelegate, the code no longer works. I get a "EXC_BAD_ACCESS" error when we hit the [db beginTransaction] line.

The flow of this code to this call:
– AltViewController Receives a button tap Event
– AltViewController tells ApplicationDelegate to execute the “addSample” method.
– ApplicationDelegate’s addSample method fails on [db beginTransaction].

Now that I’ve written this out, I am thinking the problem is that my DB gets lost after the ApplicationDelegate loads the RootView. Maybe I’m wrong though. Anyone have any ideas?

!!!!!!!!!

UPDATE!
I just altered my addSample method to include

db = [FMDatabase databaseWithPath:[self getDBPath]];
    if (![db open]) {
        NSLog(@"Could not open db.");
    }

and

[db close];

The entire transaction works now. So, the new question is: how do I make the database open ONCE and stay open across different views and viewControllers?

  • 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-05-11T16:17:41+00:00Added an answer on May 11, 2026 at 4:17 pm

    You’re having trouble because you don’t know the memory management rules yet. In this case, the databaseWithPath: method returns an autoreleased object, which is disposed of at the end of the run loop. Your db pointer still points to that invalid memory location though, which is why you’re seeing the EXC_BAD_ACCESS error when you try to access it later on.

    The good news is that memory management is actually pretty easy to learn in Cocoa. Have a look at this page for starters, it should have enough information to get you going. To solve this particular problem you would need to call the retain method on your db object after it’s created, and release it when it’s no longer needed (if you’re keeping it for the life of your application there’s nothing gained by releasing it, but it’s still good practice).

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

Sidebar

Ask A Question

Stats

  • Questions 124k
  • Answers 124k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Are you running on OS 3.0? I saw the same… May 12, 2026 at 1:19 am
  • Editorial Team
    Editorial Team added an answer It looks like you need to register Apache::Session::Memcached with Apache::Session::Wrapper,… May 12, 2026 at 1:19 am
  • Editorial Team
    Editorial Team added an answer Use DATENAME or DATEPART: SELECT DATENAME(dw,GETDATE()) -- Friday SELECT DATEPART(dw,GETDATE())… May 12, 2026 at 1:19 am

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.