- Home /
Do Sqlite have to close connection?
Hi
I'm developing a mobile game and using Sqlite(mono.data.sqlite) as native database. Is there any problem if I open database when game start and never close it?(Only this single thread game will visit the database) Such as timeout, memory leak or something else. Thank you!
Answer by zhuchun · Aug 02, 2013 at 12:41 PM
ah... I almost forget this question. Answer is if you're using native database, with single connection, then you don't need to care about its cost. Open/close it as you wish :)
Hi, what do you mean by "native database?, Im using a sqlite DB using $$anonymous$$ONO dlls. I also wanted to know if you must close an opened connection?,
@alonsoGarrote You may know SQLite only allow 1 user write to it in the same time, and in Unity, SQLite file will be lock if last write session still open, this lock will not be release until close your connection/editor/app.
So the reason why we close connection is to release that write lock, but not saving system cost.
In other words, either store your Sqlite helper as a static class(easier way, only one session, then you don't have to close it manually), or open/close it as you want(more flexible if you need to write DB between different sessions, such as apps).
Thank you, ill take into account. By the way, can you give me a hand on this?: link text I Cant make this work yet..please, its for my college project.
Your answer
Follow this Question
Related Questions
why sqlite can't conneted after build in PC (.exe) 0 Answers
Deleting the main database at runtime. 0 Answers
how to access and modify my existing database made by DB browser for SQLite in unity after build 0 Answers
SQLite Query error 0 Answers
how to use database in unity for developing android games? 0 Answers