close a session

3,330 views
Skip to first unread message

Vot

unread,
Feb 15, 2012, 12:29:51 PM2/15/12
to gree...@googlegroups.com
Hi everyone!

Im just considering to incorporate GreenDao to an application which I'm working.

I made the tutorials and now I'm using GreenDao in a prototype.

I get the SQLite error: "database is never closed"

How do you close the session?

I was looking for something like "daoSession.close()".

Greetings and thanks for your answers. 

Markus Junginger

unread,
Feb 15, 2012, 12:37:10 PM2/15/12
to gree...@googlegroups.com
The "owner" is of the SQLiteDatabase is DaoMaster, not the Session. However, DaoMaster also has no close method. You pass a SQLiteDatabase reference to DaoMaster, and you should close the SQLiteDatabase object yourself (or just let the application process be killed at some point). The rational is that you also can use the SQLiteDatabase object directly without greenDAO, so they are not really tied to each other.


Vot

unread,
Feb 16, 2012, 5:58:34 AM2/16/12
to gree...@googlegroups.com
Great!

Thank you!!

quanke

unread,
Oct 15, 2013, 11:50:24 PM10/15/13
to gree...@googlegroups.com


在 2012年2月16日星期四UTC+8上午1时37分10秒,Markus Junginger写道:
The "owner" is of the SQLiteDatabase is DaoMaster, not the Session. However, DaoMaster also has no close method. You pass a SQLiteDatabase reference to DaoMaster, and you should close the SQLiteDatabase object yourself (or just let the application process be killed at some point). The rational is that you also can use the SQLiteDatabase object directly without greenDAO, so they are not really tied to each other.

daoMaster.getDatabase().close();
daoSession.getDatabase().close();
db.close();
helper.close();
daoSession.clear();
db=null;
helper=null;
daoSession=null;
Not solve the problem. 

Mahdi Sharifi

unread,
May 5, 2015, 8:53:46 AM5/5/15
to gree...@googlegroups.com
i solve this with :
private void initializeDB() {
helper = new DaoMaster.DevOpenHelper(getActivity(), DATABASE_NAME, null);
if (db == null) {
db = helper.getWritableDatabase();
logE("initializeDB->: db==null");
} else {
if (!db.isOpen()) {
db = helper.getWritableDatabase();
logE("initializeDB->: db!=null && !db.isOpen()");
} else {
logE("initializeDB->: db!=null && db.isOpen()");
}

}
daoMaster = new DaoMaster(db);
daoSession = daoMaster.newSession();

userDao = daoSession.getUserDao();

}
private void closeDb() {
db.close();
}
before every query i call initDB then CloseDB.
:)
Reply all
Reply to author
Forward
0 new messages