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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T13:06:45+00:00 2026-06-05T13:06:45+00:00

I am running a query that looks something like this: ATTACH ‘db2’ as db;

  • 0

I am running a query that looks something like this:

ATTACH 'db2' as db;
BEGIN TRANSACTION; 
...
END TRANSACTION;

I have to do it this way because it is an error to attach in the transaction.

The problem appears to occur if another connection is already running any kind of query when the above query is issued. Then the entire query appears to fail, returning SQLITE_BUSY.

To handle this, I sleep for a while and then retry the transaction. However, now I get the error “cannot attach database within transaction”. Why is this happening?
Did the original attach succeed despite returning SQLITE_BUSY? If so, then why didn’t I get “database db2 is already in use” instead? Or is the previous transaction still open despite the fact that SQLITE_BUSY was returned? That doesn’t make sense to me, the query failed busy, so the transaction shouldn’t ever have been opened. But what else could it be?

In general the program performing the query doesn’t know what the query is, it is just a wrapper of sorts. So, I can’t do something like split the query into two parts, one to attach the database and the other to perform the rest of the query. But I’m not sure if this is the problem anyway.

  • 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-05T13:06:47+00:00Added an answer on June 5, 2026 at 1:06 pm

    I haven’t figured out exactly why this is happening, but I have found that a satisfactory solution is to call sqlite3_close() followed by sqlite3_open() after SQLITE_BUSY is returned. This gets rid of any outstanding conditions which a retry of the previous query could trip over.

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

Sidebar

Related Questions

I have a query that looks something like this: select xmlelement(rootNode, (case when XH.ID
I got this error running a query that goes against 2 tables with combined
I have situation, where running a query that filters by an indexed column in
I'm running an MySQL query that returns results based on location. However I have
I'm running a query that is timing out for first two times and returning
I am running a query that returns records from the LEFT of the EXCEPT
I am running a query that returns XML data and spools to a file.
So basically I am running a mysql query that fetches data from my database
I recently discovered that a sql query that was running fine earlier is now
I am running a sql in PHP query that is dieing with the mysql_error()

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.