Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
New Contributor
Posts: 7
Registered: ‎01-17-2011
My Device: Not Specified

SQLite multiple connections problem

Hi all,

 

I have a question regarding SQLite on BlackBerry OS 5.0 and up. Our application has two entry points, one background process that starts when the device boots and one GUI process that starts when the user clicks the application icon. Both of these processes require database access to the same database. For some reason, I can't seem to have two open connections to the database, I get a DatabaseIOException when I try to open the second connection (I also get a message that says "File System error 12"). Also, one of the SQLite statements hangs on the 'prepare' method, perhaps this is related to the two open connections, I don't know.


Can anyone help me with this?

Developer
Posts: 409
Registered: ‎06-03-2010
My Device: Z10 Red
My Carrier: Free

Re: SQLite multiple connections problem

What was the question in fact?

But you cannot open two connections for the same database
New Contributor
Posts: 7
Registered: ‎01-17-2011
My Device: Not Specified

Re: SQLite multiple connections problem

Hi Hithredin,

 

Thanks for your reply! I guess I didn't exactly ask a direct question, but I posed a problem. But your post implies that it isn't possible to open two connections at all? So does that mean that it isn't possible to access the same database from two processes?

Developer
Posts: 409
Registered: ‎06-03-2010
My Device: Z10 Red
My Carrier: Free

Re: SQLite multiple connections problem

Yes you should use a Singleton to synchronize and share access to the database.
Developer
Posts: 1,652
Registered: ‎04-08-2010
My Device: Z10 (red Limited Edition), Q10, Z30
My Carrier: Telekom.de, O2, Vodafone

Re: SQLite multiple connections problem

you should also be able to open read-only connections, what Im doing with a SQLite where another APP is storing GPS waypoints to as background APP. (ItÄs really another APP not only different access points because the GPS Tracker can run independently and can be 'used' from different other APPs. Using read-only connection I can display waypoints or routes in Map APP / Field.

 

If I want to insert / modify the GPS - Waypoints - SQLite DB from other APPs I'm using services provided by the GPS Tracker APP via remote (global) commands (OS 6).

 

also it can happen that there are some threads running from GPS Tracker APP (one tracking and storing waypoints, another one doing reverse geocoding and updating records) - in this case I'm using a synchronized object as mentioned in other replies.

-------------------------------------------------------------------------------
ekke (independent software architect, rosenheim, germany)

BlackBerry Elite Developer
BlackBerry Platinum Enterprise Partner
International Development Mobile Apps BlackBerry 10 Cascades
Cascades - Workshops / Trainings / Bootcamps

blog: http://ekkes-corner.org videos: http://www.youtube.com/user/ekkescorner http://vimeo.com/ekkescorner/videos
bb10-development: http://appbus.org Twitter: @ekkescorner
New Contributor
Posts: 7
Registered: ‎01-17-2011
My Device: Not Specified

Re: SQLite multiple connections problem

 

Thanks for all of your replies! However, I haven't been able to fix it yet. i've tried putting the database helper in the runtime store and I've also tried read-only connections, but the system still seems to hang on the prepare method of one of the sqlitestatements. The debugger shows the following stack after a call to prepare():

 

pendingOperation.wait();

prepareAsync();

prepare();

[...]



It seems like there's deadlock or something, but I don't know what could be causing it. I'm sure that only one of the processes is accessing the database at the same time.

New Contributor
Posts: 7
Registered: ‎01-17-2011
My Device: Not Specified

Re: SQLite multiple connections problem

[ Edited ]
Trusted Contributor
Posts: 141
Registered: ‎02-15-2012
My Device: 9800
My Carrier: Airtel

Re: SQLite multiple connections problem

Hi,

You are opening your database again without closing it properly so that you are getting these type of problems. So you hae to do one database handling in the block and when you are try to using any database then after opening database in try block, make sure that you are closing database in the finally block.

 

If you are using threads and getting any runtime errors, then use synchronized block for each database handling code where you are opening and closing database. At the last of synchronized block, use notifyall()  to run all blocks. This would very useful to you.

 

Thanks,

 

Ankit

 

Press like button,. if you satisfied.