- Home /
SQLite Connections Staying Open
I am using SQLite in a project and every time I open a connection with the database I take advantage of the IDisposable interface with a using statement. But even though I do that unity still keeps a handle to the database open .The handles stay open until I close Unity . Here is an example of how I am accessing the SQLLite db:
After a doing a couple operations like the above I can see that Unity has many handles open to the database file by using the Process Explorer.
I would love to here some ideas as to why this would be happening. As a side note I am using dapper as an ORM.
Answer by jamesmac64 · Mar 14, 2020 at 09:10 PM
First, I'll say now that I am not an sqllite user, but I've worked with a few databases (MS SQL, MySql, and SimpleDatabase), in game development, with my own server core and with UE. Currently working with MySql in Unity 2018. But I know db behaviors and how to work with them.
SqlLite tends to keep connections open in order to speed things up. You can try using the Close() from the created connection, which MAY work. From my understanding of SQlLite though, the catch is that SqlLite can still maintain the connection if it thinks it will need it to keep transaction speeds up. But from my own personal experience, it is best to open a connection, perform the transaction or transactions needed, and then close the connection. In this case, to the file rather than a database engine.
I hope that helps.
Thanks for the response. I was under the impression that using the 'using' statement was supposed to close the connection no matter what once the execution inside the brackets completed? Is this not the case with sqlite?
Your answer
![](https://koobas.hobune.stream/wayback/20220612224948im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
SqliteConnection And SQLiteConnection throw MissingMethodException 1 Answer
SQLite Except: The database file is locked 1 Answer
Database (SQLite) Setup for Unity 0 Answers
SQLite Database is not working after standalone build 1 Answer
How to connect SQL Server with Unity?,How to Connect SQLServer with unity? 0 Answers