title: Corrupt H2 Database
body: <p>I'm using H2 1.3.172 on a Windows machine with the following connection string:</p>
  
  <pre><code>jdbc:h2:tcp://localhost/dev/*****;LOG=0;UNDO_LOG=0;DB_CLOSE_ON_EXIT=TRUE;IGNORECASE=TRUE;OPTIMIZE_REUSE_RESULTS=0;QUERY_TIMEOUT=180000;MAX_OPERATION_MEMORY=0;MAX_MEMORY_ROWS=30000;COMPRESS_LOB=NO;LOCK_MODE=0;MULTI_THREADED=0;CACHE_SIZE=1048576;TRACE_LEVEL_FILE=2;
  </code></pre>
  
  <p>I receive the following exception when trying to connect to an existing database:</p>
  
  <pre><code>General error: "java.lang.NullPointerException"
  </code></pre>
  
  <p>Scenario:</p>
  
  <ul>
  <li>I have a highly complex process around the H2 database. </li>
  <li>It all works fine with no issues.</li>
  <li>When the IIS reaches an idle session timeout an attempt to close any
  open connections is made.</li>
  <li><p>Failure as shown in the trace log (last few lines):</p>
  
  <pre><code>06-02 15:32:33 jdbc[2]: 
  /*SQL #:1*/UPDATE UserTokens SET Timestamp_Expires = DATEADD('MINUTE', 20, Timestamp_Expires) WHERE Token = '1812493846';
  06-02 15:32:33 jdbc[2]: 
  /*SQL #:1*/SELECT QC_Result FROM QueryCache WHERE QC_Query = 'COMMAND::usp_Engine_Metrics_FindByName||PARAM::@name%%VarChar%%50%%Hands Played||';
  06-02 15:32:33 jdbc[2]: 
  /*SQL #:1*/SELECT RC_Result FROM ResultsCache WHERE RC_ID = '5/2/2013 12:00:00 AM_6/1/2013 11:59:59 PM__Hands Played|_Day_True____0';
  06-02 15:32:33 jdbc[2]: 
  /*SQL #:1*/UPDATE UserTokens SET Timestamp_Expires = DATEADD('MINUTE', 20, Timestamp_Expires) WHERE Token = '1812493846';
  06-02 15:32:33 jdbc[2]: 
  /*SQL #:1*/INSERT INTO UserState (US_ID, US_State) VALUES ('b72e861a3c04a5b1ab8282eb6605b9e0','{\"view\":\"dashboard\",\"dashboardID\":21,\"panelID\":-1,\"reportID\":-1,\"fromdate\":null,\"todate\":null,\"guid\":\"b72e861a3c04a5b1ab8282eb6605b9e0\",\"timestamp\":\"2013-06-02T12:32:33.183Z\"}');
  06-02 15:35:49 jdbc[2]: 
  /*SQL */COMMIT;
  06-02 15:35:49 jdbc[2]: 
  /*SQL */ROLLBACK;
  06-02 15:35:49 database: disconnecting session #2
  06-02 15:35:49 database: closing C:/Program Files (x86)/H2/service/dev/JarvisDB
  06-02 15:35:49 database: close
  java.lang.ArrayIndexOutOfBoundsException: 2048
  at org.h2.store.Data.writeValue(Data.java:406)
  at org.h2.store.Data.writeValue(Data.java:640)
  at org.h2.index.PageBtreeIndex.writeRow(PageBtreeIndex.java:396)
  at org.h2.index.PageBtreeNode.writeData(PageBtreeNode.java:446)
  at org.h2.index.PageBtreeNode.write(PageBtreeNode.java:420)
  at org.h2.store.PageStore.writeBack(PageStore.java:1012)
  at org.h2.store.PageStore.writeBack(PageStore.java:412)
  at org.h2.store.PageStore.checkpoint(PageStore.java:430)
  at org.h2.engine.Database.closeOpenFilesAndUnlock(Database.java:1211)
  at org.h2.engine.Database.close(Database.java:1164)
  at org.h2.engine.Database.removeSession(Database.java:1043)
  at org.h2.engine.Session.close(Session.java:617)
  at org.h2.server.TcpServerThread.closeSession(TcpServerThread.java:177)
  at org.h2.server.TcpServerThread.process(TcpServerThread.java:272)
  at org.h2.server.TcpServerThread.run(TcpServerThread.java:151)
  at java.lang.Thread.run(Unknown Source)
  06-02 15:35:49 database: closed
  06-02 15:35:49 database: disconnected session #2
  </code></pre></li>
  </ul>
  
  <p>I assume the issue with me closing the connection, but I could really use some guidance as to the exact cause and workaround.</p>
  
  <p>Many thanks,</p>