Get connection failed - The database is read only [90097-159]

1,636 views
Skip to first unread message

Steve Luo

unread,
Nov 18, 2011, 9:15:51 PM11/18/11
to H2 Database
Hi,

I use h2 (version: 1.3.159) in embedded mode. Sometimes when trying to
get connection with the database (connection string is: jdbc:h2:D:/
QuickBuild/builds/2236/reports/jira/DEFAULT/jira;ACCESS_MODE_DATA=r),
below exception raised:

org.h2.jdbc.JdbcSQLException: The database is read only [90097-159]
at
org.h2.message.DbException.getJdbcSQLException(DbException.java:329)
at org.h2.message.DbException.get(DbException.java:169)
at org.h2.message.DbException.get(DbException.java:146)
at org.h2.message.DbException.get(DbException.java:135)
at org.h2.engine.Database.checkWritingAllowed(Database.java:1626)
at org.h2.store.PageStore.logUndo(PageStore.java:996)
at org.h2.index.PageDataLeaf.create(PageDataLeaf.java:92)
at org.h2.index.PageDataIndex.getPage(PageDataIndex.java:227)
at org.h2.index.PageDataIndex. (PageDataIndex.java:81)
at org.h2.table.RegularTable. (RegularTable.java:92)
at org.h2.store.PageStore.openMetaIndex(PageStore.java:1511)
at org.h2.store.PageStore.recover(PageStore.java:1328)
at org.h2.store.PageStore.openExisting(PageStore.java:349)
at org.h2.store.PageStore.open(PageStore.java:273)
at org.h2.engine.Database.getPageStore(Database.java:2049)
at org.h2.engine.Database.open(Database.java:553)
at org.h2.engine.Database.openDatabase(Database.java:220)
at org.h2.engine.Database. (Database.java:215)
at org.h2.engine.Engine.openSession(Engine.java:56)
at org.h2.engine.Engine.openSession(Engine.java:159)
at org.h2.engine.Engine.createSessionAndValidate(Engine.java:138)
at org.h2.engine.Engine.createSession(Engine.java:121)
at org.h2.engine.Engine.createSession(Engine.java:28)
at
org.h2.engine.SessionRemote.connectEmbeddedOrServer(SessionRemote.java:
285)
at org.h2.jdbc.JdbcConnection. (JdbcConnection.java:110)
at org.h2.jdbc.JdbcConnection. (JdbcConnection.java:94)
at org.h2.Driver.connect(Driver.java:72)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at
com.pmease.quickbuild.plugin.report.engine.datastore.ConnectionManager.getConnection(ConnectionManager.java:
23)

What would be the problem?

Thomas Mueller

unread,
Nov 22, 2011, 2:24:53 PM11/22/11
to h2-da...@googlegroups.com
Hi,

The problem is that the database was not closed before. Now, when trying to open the database in read-only mode, recovery is required. But recovery is not possible when the database is read-only (when using access_mode_data=r).

Regards,
Thomas

Steve Luo

unread,
Jan 3, 2012, 9:08:31 AM1/3/12
to H2 Database
Hi Thomas,

Thank you for the reply. I also want to know how to detect the
database which was closed correctly or not? By detecting *.lock.db
file or something else? Is it possible when the database was corrupted
will also cause such error?

Best Regards,
Steve

On 2011年11月23日, 上午3时24分, Thomas Mueller <thomas.tom.muel...@gmail.com>
wrote:

Thomas Mueller

unread,
Jan 9, 2012, 3:06:59 AM1/9/12
to h2-da...@googlegroups.com
Hi,

It's not so easy to detect. If the .lock.db file still exists, then it wasn't closed normally. But possibly the file is gone (after calling "shutdown immediately" it's gone). One solution to ensure it's closed normally is to open and close it normally. Another is to run the Recover tool and check the transaction log is empty.

Is it possible when the database was corrupted
will also cause such error?

No, it would be a different error message. 

Regards,
Thomas
Reply all
Reply to author
Forward
0 new messages