title: Database may be already in use: “Locked by another process” when starting two grails apps from tomcat
body: <p>I deployed two grails apps into Tomcat. While starting up the app, I saw the following error. And my app failed to start. </p>
  
  <p>org.h2.jdbc.JdbcSQLException: Database may be already in use: "Locked by another process". Possible solutions: close all other connection(s); use the server mode [90020-176]</p>
  
  <p>Here is the DataSource.Groovy. </p>
  
  <pre><code>dataSource {
      pooled = true
      jmxExport = true
      driverClassName = "org.h2.Driver"
      username = "sa"
      password = ""
  }
  hibernate {
      cache.use_second_level_cache = true
      cache.use_query_cache = false
  //    cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory' // Hibernate 3
      cache.region.factory_class = 'org.hibernate.cache.ehcache.EhCacheRegionFactory' // Hibernate 4
      singleSession = true // configure OSIV singleSession mode
      flush.mode = 'manual' // OSIV session flush mode outside of transactional context
  }
  
  // environment specific settings
  environments {
      development {
          dataSource {
              dbCreate = "create-drop" // one of 'create', 'create-drop', 'update', 'validate', ''
              url = "jdbc:h2:mem:devDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE"
          }
      }
      test {
          dataSource {
              dbCreate = "update"
              url = "jdbc:h2:mem:testDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE"
          }
      }
      production {
          dataSource {
              dbCreate = "update"
              url = "jdbc:h2:prodDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE"
              properties {
                 // See http://grails.org/doc/latest/guide/conf.html#dataSource for documentation
                 jmxEnabled = true
                 initialSize = 5
                 maxActive = 50
                 minIdle = 5
                 maxIdle = 25
                 maxWait = 10000
                 maxAge = 10 * 60000
                 timeBetweenEvictionRunsMillis = 5000
                 minEvictableIdleTimeMillis = 60000
                 validationQuery = "SELECT 1"
                 validationQueryTimeout = 3
                 validationInterval = 15000
                 testOnBorrow = true
                 testWhileIdle = true
                 testOnReturn = false
                 jdbcInterceptors = "ConnectionState"
                 defaultTransactionIsolation = java.sql.Connection.TRANSACTION_READ_COMMITTED
              }
          }
      }
  }
  </code></pre>
  
  <p>If I change </p>
  
  <pre><code>dbCreate = "update"
  </code></pre>
  
  <p>to</p>
  
  <pre><code>dbCreate = "create-drop" 
  </code></pre>
  
  <p>in production mode.</p>
  
  <p>I can start either one of the two apps but not both.</p>
  
  <p>Seems the two embeded H2 databases are conflicting with each other?</p>