Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by jXD · Jul 23, 2013 at 10:10 AM · databaseexceptionsqlitelocked

Sqlite databases getting locked by Unity.

Hi guys,

Whenever I try to input values into my sqlite database from unity, it always throws an exception: SqliteException: The database file is locked I still can read from it, but whenever I try to write into the db, Unity will hang for 10 secs and then that error pops up in the console. Here is my code:

 public SqliteDataReader InsertInto(string tableName, string[] values)
     {
         string query = "INSERT INTO " + tableName + " VALUES(" + values[0];
         for (int i = 1; i < values.Length; ++i)
         {
             query += ", " + values[i];
         }
         query += ")";
         Debug.Log("Inserted!");
         return ExecuteQuery(query);
     }

I also understand that this might occur due to the closing of connections being wrong(which I highly doubt so, but to be sure heres the closing code:

 public void CloseSqlConnection()
     {
         reader.Close();
         reader = null;
         dbCommand.Dispose();
         dbCommand = null;
         dbConnection.Close();
         dbConnection = null;
         GC.Collect();
         Debug.Log("Disconnected from db.");
     }

This problem occurs even when I restart my PC, and launch Unity for the first time, so I doubt its the connection problem. Also, the database is in the proper folder, and it works fine(as I can read from it). It was working fine a few days back, and now it just decided to break.

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Jamora · Jul 23, 2013 at 10:56 AM 0
Share

Where/how often is your CloseSqlConnection() called?

avatar image Graham-Dunnett ♦♦ · Jul 23, 2013 at 10:59 AM 0
Share

If you use the sqlite command line app, are you able to edit the database directly. I mean, is this uniquely a problem when you connect from script code. Unity itself doesn't know what a sqlite db is. I'd assume it's a permissions thing on the db.

avatar image jXD · Jul 24, 2013 at 11:36 PM 0
Share

I'm using the sqlite manager script from the unify wiki. I found the c# version on the unity forums some time back. As for the closesqlconnection(), I'm using this from an editorwindow, so I call it every onlostfocus() and reconnect every onfocus().

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Jamora · Jul 25, 2013 at 09:04 AM

I made a little test script to see how many times OnFocus is called when the window is opened the first time. Turns out it is called twice. So the reason why your database is locked for writing is because you have an open, possibly leaked connection to it. After the first time On(Lost)Focus behaves as expected.

I think something along these lines would work better:

 [MenuItem("Item/Item")]
 public static void Init(){
     GetWindow<TestScript>();
     //Initialize connection.
 }
 
 void OnFocus(){
     //If (connection == null)
     //Initialize connection.
 }
 
 void OnLostFocus(){
     //Close connection.
 }
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image jXD · Jul 27, 2013 at 01:22 AM 0
Share

Thanks, that worked perfectly. I also found that running as ad$$anonymous$$ solves it temporarily, but changing my script to that worked better. Thanks!

avatar image
0

Answer by jXD · Jul 24, 2013 at 11:40 PM

I'm using the sqlite manager script from the unify wiki. I found the c# version on the unity forums some time back. As for the closesqlconnection(), I'm using this from an editorwindow, so I call it every onlostfocus() and reconnect every onfocus().

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

17 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

A node in a childnode? 1 Answer

how to make the build in android which can access the local database sqlite 0 Answers

Game Database. SQLite, XML, JSON or PlayerPrefs? 1 Answer

database visualization 1 Answer

SqliteException: Unable to open the database file - Ready-made DB Provided To Access 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges