Python sqlite3 database lockedHow do I unlock a SQLite database?How to list the tables in a SQLite database file that was opened with ATTACH?Calling an external command in PythonWhat are metaclasses in Python?Finding the index of an item given a list containing it in PythonWhat is the difference between Python's list methods append and extend?How can I safely create a nested directory?Does Python have a ternary conditional operator?How to get the current time in PythonHow can I make a time delay in Python?Does Python have a string 'contains' substring method?

How can my android "die" permanently?

What is the better way to use Optional in conditions?

Cascading Repair Costs following Blown Head Gasket on a 2004 Subaru Outback

What does "play with your toy’s toys" mean?

Has there been any indication at all that further negotiation between the UK and EU is possible?

Why do textbooks often include the solutions to odd or even numbered problems but not both?

Find the probability that the 8th woman to appear is in 17th position.

How do I turn off a repeating trade?

(Newbie question)Why is voltage measurement of circuit different when switch is on?

Is this one of the engines from the 9/11 aircraft?

Folding basket - is there such a thing?

Why do some professors with PhDs leave their professorships to teach high school?

What is the legal status of travelling with methadone in your carry-on?

What was the Shuttle Carrier Aircraft escape tunnel?

Can Ogre clerics use Purify Food and Drink on humanoid characters?

How would modern naval warfare have to have developed differently for battleships to still be relevant in the 21st century?

Would it be a copyright violation if I made a character’s full name refer to a song?

How do I professionally let my manager know I'll quit over smoking in the office?

What does the hyphen "-" mean in "tar xzf -"?

How many people are necessary to maintain modern civilisation?

Trainee keeps missing deadlines for independent learning

Applicability of Lagrange Multipliers in the analysis of large-scale MILPs?

Find the C-factor of a vote

Given a cell in a Voronoi diagram, which point did it come from?



Python sqlite3 database locked


How do I unlock a SQLite database?How to list the tables in a SQLite database file that was opened with ATTACH?Calling an external command in PythonWhat are metaclasses in Python?Finding the index of an item given a list containing it in PythonWhat is the difference between Python's list methods append and extend?How can I safely create a nested directory?Does Python have a ternary conditional operator?How to get the current time in PythonHow can I make a time delay in Python?Does Python have a string 'contains' substring method?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








2















I am using Python 3 and sqlite3 on Windows. I am developing a small application that is using a database to store contacts. I notice that if the application closes forcibly (either by error or ending via task manager) that I get the sqlite3 error (sqlite3.OperationalError: database is locked).



I imagine this is because I am not properly closing the database connection before the application has closed. I have tried this:



 connection = sqlite3.connect(dbFile.db)
connection.commit()
connection.close()


and then trying to reopen the connection, but the locked database remains. Is there anyway to close the database before a crash? Or a way to unlock the database in the application? Right now the only solution I have is to delete the database and start over (which will not really work long term).



Thanks!










share|improve this question






















  • is the file in a mounted directory? sometime that can be an issue

    – MEdwin
    Mar 25 at 9:03











  • The file is on a secondary hard drive (d). This could be the case. Is there any means of avoiding this or should I always save these files on the c drive. Thanks!

    – SpaceyEeyore
    Mar 26 at 0:25

















2















I am using Python 3 and sqlite3 on Windows. I am developing a small application that is using a database to store contacts. I notice that if the application closes forcibly (either by error or ending via task manager) that I get the sqlite3 error (sqlite3.OperationalError: database is locked).



I imagine this is because I am not properly closing the database connection before the application has closed. I have tried this:



 connection = sqlite3.connect(dbFile.db)
connection.commit()
connection.close()


and then trying to reopen the connection, but the locked database remains. Is there anyway to close the database before a crash? Or a way to unlock the database in the application? Right now the only solution I have is to delete the database and start over (which will not really work long term).



Thanks!










share|improve this question






















  • is the file in a mounted directory? sometime that can be an issue

    – MEdwin
    Mar 25 at 9:03











  • The file is on a secondary hard drive (d). This could be the case. Is there any means of avoiding this or should I always save these files on the c drive. Thanks!

    – SpaceyEeyore
    Mar 26 at 0:25













2












2








2








I am using Python 3 and sqlite3 on Windows. I am developing a small application that is using a database to store contacts. I notice that if the application closes forcibly (either by error or ending via task manager) that I get the sqlite3 error (sqlite3.OperationalError: database is locked).



I imagine this is because I am not properly closing the database connection before the application has closed. I have tried this:



 connection = sqlite3.connect(dbFile.db)
connection.commit()
connection.close()


and then trying to reopen the connection, but the locked database remains. Is there anyway to close the database before a crash? Or a way to unlock the database in the application? Right now the only solution I have is to delete the database and start over (which will not really work long term).



Thanks!










share|improve this question














I am using Python 3 and sqlite3 on Windows. I am developing a small application that is using a database to store contacts. I notice that if the application closes forcibly (either by error or ending via task manager) that I get the sqlite3 error (sqlite3.OperationalError: database is locked).



I imagine this is because I am not properly closing the database connection before the application has closed. I have tried this:



 connection = sqlite3.connect(dbFile.db)
connection.commit()
connection.close()


and then trying to reopen the connection, but the locked database remains. Is there anyway to close the database before a crash? Or a way to unlock the database in the application? Right now the only solution I have is to delete the database and start over (which will not really work long term).



Thanks!







python python-3.x sqlite






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 25 at 8:55









SpaceyEeyoreSpaceyEeyore

113 bronze badges




113 bronze badges












  • is the file in a mounted directory? sometime that can be an issue

    – MEdwin
    Mar 25 at 9:03











  • The file is on a secondary hard drive (d). This could be the case. Is there any means of avoiding this or should I always save these files on the c drive. Thanks!

    – SpaceyEeyore
    Mar 26 at 0:25

















  • is the file in a mounted directory? sometime that can be an issue

    – MEdwin
    Mar 25 at 9:03











  • The file is on a secondary hard drive (d). This could be the case. Is there any means of avoiding this or should I always save these files on the c drive. Thanks!

    – SpaceyEeyore
    Mar 26 at 0:25
















is the file in a mounted directory? sometime that can be an issue

– MEdwin
Mar 25 at 9:03





is the file in a mounted directory? sometime that can be an issue

– MEdwin
Mar 25 at 9:03













The file is on a secondary hard drive (d). This could be the case. Is there any means of avoiding this or should I always save these files on the c drive. Thanks!

– SpaceyEeyore
Mar 26 at 0:25





The file is on a secondary hard drive (d). This could be the case. Is there any means of avoiding this or should I always save these files on the c drive. Thanks!

– SpaceyEeyore
Mar 26 at 0:25












1 Answer
1






active

oldest

votes


















0














If your application closes forcibly, surly you wouldn't want to commit your current transaction, instead rollback to insure nothing breaks?



After a signal for a close has been caught, try the following:



connection.rollback()
connection.close()





share|improve this answer























  • the code except I had found somewhere else (you're definitely right in that I don't want to commit, I am simply trying to release the lock). The issue I'm having is when developing this application I may not have caught an error and the application already has forcibly closed and want a way to unlock or reset without having to delete the file.

    – SpaceyEeyore
    Mar 26 at 0:24











  • Check out this. It seem that your program dying during an operation that locks the database is undefined behaviour. Options I could suggest: Improve error handling in your program to insure you dont forcibly quit during a heavy sql operation. After an unexpected quit, on startup have your program check if there is a process using the database, and kill it.

    – Alex Hodges
    Apr 1 at 12:00












  • That is a good suggestion. I think it would be wise to better error handling, issue arises during my debugging sessions when I have been adding new code and wanting to test a new feature.

    – SpaceyEeyore
    Apr 2 at 19:06













Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55334178%2fpython-sqlite3-database-locked%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














If your application closes forcibly, surly you wouldn't want to commit your current transaction, instead rollback to insure nothing breaks?



After a signal for a close has been caught, try the following:



connection.rollback()
connection.close()





share|improve this answer























  • the code except I had found somewhere else (you're definitely right in that I don't want to commit, I am simply trying to release the lock). The issue I'm having is when developing this application I may not have caught an error and the application already has forcibly closed and want a way to unlock or reset without having to delete the file.

    – SpaceyEeyore
    Mar 26 at 0:24











  • Check out this. It seem that your program dying during an operation that locks the database is undefined behaviour. Options I could suggest: Improve error handling in your program to insure you dont forcibly quit during a heavy sql operation. After an unexpected quit, on startup have your program check if there is a process using the database, and kill it.

    – Alex Hodges
    Apr 1 at 12:00












  • That is a good suggestion. I think it would be wise to better error handling, issue arises during my debugging sessions when I have been adding new code and wanting to test a new feature.

    – SpaceyEeyore
    Apr 2 at 19:06















0














If your application closes forcibly, surly you wouldn't want to commit your current transaction, instead rollback to insure nothing breaks?



After a signal for a close has been caught, try the following:



connection.rollback()
connection.close()





share|improve this answer























  • the code except I had found somewhere else (you're definitely right in that I don't want to commit, I am simply trying to release the lock). The issue I'm having is when developing this application I may not have caught an error and the application already has forcibly closed and want a way to unlock or reset without having to delete the file.

    – SpaceyEeyore
    Mar 26 at 0:24











  • Check out this. It seem that your program dying during an operation that locks the database is undefined behaviour. Options I could suggest: Improve error handling in your program to insure you dont forcibly quit during a heavy sql operation. After an unexpected quit, on startup have your program check if there is a process using the database, and kill it.

    – Alex Hodges
    Apr 1 at 12:00












  • That is a good suggestion. I think it would be wise to better error handling, issue arises during my debugging sessions when I have been adding new code and wanting to test a new feature.

    – SpaceyEeyore
    Apr 2 at 19:06













0












0








0







If your application closes forcibly, surly you wouldn't want to commit your current transaction, instead rollback to insure nothing breaks?



After a signal for a close has been caught, try the following:



connection.rollback()
connection.close()





share|improve this answer













If your application closes forcibly, surly you wouldn't want to commit your current transaction, instead rollback to insure nothing breaks?



After a signal for a close has been caught, try the following:



connection.rollback()
connection.close()






share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 25 at 11:49









Alex HodgesAlex Hodges

504 bronze badges




504 bronze badges












  • the code except I had found somewhere else (you're definitely right in that I don't want to commit, I am simply trying to release the lock). The issue I'm having is when developing this application I may not have caught an error and the application already has forcibly closed and want a way to unlock or reset without having to delete the file.

    – SpaceyEeyore
    Mar 26 at 0:24











  • Check out this. It seem that your program dying during an operation that locks the database is undefined behaviour. Options I could suggest: Improve error handling in your program to insure you dont forcibly quit during a heavy sql operation. After an unexpected quit, on startup have your program check if there is a process using the database, and kill it.

    – Alex Hodges
    Apr 1 at 12:00












  • That is a good suggestion. I think it would be wise to better error handling, issue arises during my debugging sessions when I have been adding new code and wanting to test a new feature.

    – SpaceyEeyore
    Apr 2 at 19:06

















  • the code except I had found somewhere else (you're definitely right in that I don't want to commit, I am simply trying to release the lock). The issue I'm having is when developing this application I may not have caught an error and the application already has forcibly closed and want a way to unlock or reset without having to delete the file.

    – SpaceyEeyore
    Mar 26 at 0:24











  • Check out this. It seem that your program dying during an operation that locks the database is undefined behaviour. Options I could suggest: Improve error handling in your program to insure you dont forcibly quit during a heavy sql operation. After an unexpected quit, on startup have your program check if there is a process using the database, and kill it.

    – Alex Hodges
    Apr 1 at 12:00












  • That is a good suggestion. I think it would be wise to better error handling, issue arises during my debugging sessions when I have been adding new code and wanting to test a new feature.

    – SpaceyEeyore
    Apr 2 at 19:06
















the code except I had found somewhere else (you're definitely right in that I don't want to commit, I am simply trying to release the lock). The issue I'm having is when developing this application I may not have caught an error and the application already has forcibly closed and want a way to unlock or reset without having to delete the file.

– SpaceyEeyore
Mar 26 at 0:24





the code except I had found somewhere else (you're definitely right in that I don't want to commit, I am simply trying to release the lock). The issue I'm having is when developing this application I may not have caught an error and the application already has forcibly closed and want a way to unlock or reset without having to delete the file.

– SpaceyEeyore
Mar 26 at 0:24













Check out this. It seem that your program dying during an operation that locks the database is undefined behaviour. Options I could suggest: Improve error handling in your program to insure you dont forcibly quit during a heavy sql operation. After an unexpected quit, on startup have your program check if there is a process using the database, and kill it.

– Alex Hodges
Apr 1 at 12:00






Check out this. It seem that your program dying during an operation that locks the database is undefined behaviour. Options I could suggest: Improve error handling in your program to insure you dont forcibly quit during a heavy sql operation. After an unexpected quit, on startup have your program check if there is a process using the database, and kill it.

– Alex Hodges
Apr 1 at 12:00














That is a good suggestion. I think it would be wise to better error handling, issue arises during my debugging sessions when I have been adding new code and wanting to test a new feature.

– SpaceyEeyore
Apr 2 at 19:06





That is a good suggestion. I think it would be wise to better error handling, issue arises during my debugging sessions when I have been adding new code and wanting to test a new feature.

– SpaceyEeyore
Apr 2 at 19:06



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid …


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55334178%2fpython-sqlite3-database-locked%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to preserve electronics (computers, tablets and phones) for hundreds of years Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) The network's official Twitter account is up and running again. What content…How might modern humans leave a message for 50,000 years?How would an aquatic race develop computers?How do we make computers care for human life?Keeping supplies for 1000 yearsWhat will cell phones become in 100 years?What body armor protects against a laser?Could a society attain 1800s technology if limited to using copper and bronze?Electricity power (magic) and electronicsScavenging metal resources in post-apocalypse after 100 yearsWhy would precursors create devices that can survive and still work after hundreds of years?

155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해

Convert JSON to MapSimplest way to convert a string representing JSON array into Java array List of key value pairsHow to take String JSON values into HashMapConvert a JSON String to a HashMapCreating BSON object from JSON stringJSONObject - How to get a value ?Better Map ConstructorReading JSON from Url javaUpdate columns if input values are not null otherwise ignore and keep the existing values of column in databaseHow to store object represented as Json string into Couchbase Lite?Go JSON into MapHow do I efficiently iterate over each entry in a Java Map?Sort a Map<Key, Value> by valuesHow to round a number to n decimal places in JavaCan comments be used in JSON?How do I read / convert an InputStream into a String in Java?How can I pretty-print JSON in a shell script?What is the correct JSON content type?How can I deserialize JSON to a simple Dictionary<string,string> in ASP.NET?Why does Google prepend while(1); to their JSON responses?Parse JSON in JavaScript?