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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:28:24+00:00 2026-05-26T15:28:24+00:00

I have a service running that contains an SQLite DB and a Content Observer

  • 0

I have a service running that contains an SQLite DB and a Content Observer registered to the DB’s URI. The Content Observer uses an SQLiteOpenHelper to query the data from the DB. So when new data is put into the services DB from other application via Content Provider the changed cursor will be observed and query the data to process. The problem is if I insert data at a fast pace from other applications I end up with both the Content Observer and Content Provider opening the DB and causes an SQLite error with a database lock.

I am using the getReadable and getWritable methods and closing the DB and any cursors after they are used. It just seem that the CP and CO are not in sync. How can I fix this problem?

UPDATE
When I test this on a Motorola Atrix I have no problems. When I test it on a Samsung Galaxy Tab I get problems. On the Atrix it appears from my debug tags in the catlog that both the CO and the CP have the DB open at the same time… but still not problem like there is with the Galaxy. The Galaxy gives me this error:

11-04 12:12:13.490: ERROR/SqliteDatabaseCpp(19978): sqlite3_open_v2("/data/data/my.package/databases/raw_data_buffer.db", &handle, 6, NULL) failed
11-04 12:12:13.490: ERROR/SQLiteDatabase(19978): Failed to open the database. closing it.
11-04 12:12:13.490: ERROR/SQLiteDatabase(19978): android.database.sqlite.SQLiteDatabaseLockedException: database is locked
11-04 12:12:13.490: ERROR/SQLiteDatabase(19978):     at android.database.sqlite.SQLiteDatabase.dbopen(Native Method)
11-04 12:12:13.490: ERROR/SQLiteDatabase(19978):     at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:983)
11-04 12:12:13.490: ERROR/SQLiteDatabase(19978):     at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:956)
11-04 12:12:13.490: ERROR/SQLiteDatabase(19978):     at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:1021)
11-04 12:12:13.490: ERROR/SQLiteDatabase(19978):     at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:750)
11-04 12:12:13.490: ERROR/SQLiteDatabase(19978):     at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:221)
11-04 12:12:13.490: ERROR/SQLiteDatabase(19978):     at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:149)
11-04 12:12:13.490: ERROR/SQLiteDatabase(19978):     at my.package.RawDataBufferDatabaseHelper.insert(RawDataBufferDatabaseHelper.java:93)
11-04 12:12:13.490: ERROR/SQLiteDatabase(19978):     at my.package.NetService$NetworkPollingRunnable.run(NetService.java:166)
11-04 12:12:13.490: ERROR/SQLiteDatabase(19978):     at java.lang.Thread.run(Thread.java:1020)
11-04 12:12:13.490: WARN/dalvikvm(19978): threadid=9: thread exiting with uncaught exception (group=0x40189760)
11-04 12:12:13.490: ERROR/AndroidRuntime(19978): FATAL EXCEPTION: Thread-14
11-04 12:12:13.490: ERROR/AndroidRuntime(19978): android.database.sqlite.SQLiteDatabaseLockedException: database is locked
11-04 12:12:13.490: ERROR/AndroidRuntime(19978):     at android.database.sqlite.SQLiteDatabase.dbopen(Native Method)
11-04 12:12:13.490: ERROR/AndroidRuntime(19978):     at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:983)
11-04 12:12:13.490: ERROR/AndroidRuntime(19978):     at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:956)
11-04 12:12:13.490: ERROR/AndroidRuntime(19978):     at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:1021)
11-04 12:12:13.490: ERROR/AndroidRuntime(19978):     at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:750)
11-04 12:12:13.490: ERROR/AndroidRuntime(19978):     at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:221)
11-04 12:12:13.490: ERROR/AndroidRuntime(19978):     at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:149)
11-04 12:12:13.490: ERROR/AndroidRuntime(19978):     at my.package.RawDataBufferDatabaseHelper.insert(RawDataBufferDatabaseHelper.java:93)

  • 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-26T15:28:25+00:00Added an answer on May 26, 2026 at 3:28 pm

    Closing the cursors really doesn’t have any affect on anything in this case. Don’t have your CO’s directly accessing the database. Make every piece of your code go through the ContentProvider and in your content provider only have one writeable and one readable connection open (make these instance variables). That should keep everything consistent because then you’ll only have one db connection that you’re going through. As long as you’re using the same db connection you’re fine. The sqlite methods are reentrant.

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

Sidebar

Related Questions

I have a service running in my Android application which contains a HashMap that
I have an ASP.NET web service running that accepts both HTTP POST and SOAP
I have a web service that is running on IIS (6 or 7, doesn't
I have a .NET Web Service running in VS2005 and a client that consumes
I have a WCF service method that's running in a worker thread I spin
We have an application that has a WCF service (*.svc) running on IIS7 and
I have a windows service that runs various system monitoring operations. However, when running
I have a dotnet windows service that's currently hung, but running. Is there anyway
Problem: I have a python script that I have running as a service. It's
I'm running Windows 2003 Service Pack 2. I have a batch file that runs

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.