2

I have the same scenario as this one: H2 Database multiple connections. It's the classic "Microsoft Access database on network share" approach.

I have an application that should be installed on several clients within a LAN. During the installation, the user is asked to provide the database location on a network share.

I would like to avoid a separate database server/service installation. In the simplest case, the user just installs the application on 2 computers, both having access to a common network share (can be located on a 3rd computer/server).

Now it seems to me that the automatic mixed mode is what I am looking for, but I am not quite sure. I am mainly looking for confirmation of my understanding, since it isn't explicitly stated in the docs.

So, is the AUTO_SERVER mode the correct (intended/best) way to connect to an H2 database located on a network share from multiple clients running on different machines within the same LAN?

Or have I got this totally wrong and is this something I should not try at all?

Thanks for your time.

Community
  • 1
  • 1
Reto Höhener
  • 5,419
  • 4
  • 39
  • 79
  • 2
    That's how I read [it](http://www.h2database.com/html/features.html#auto_mixed_mode); it seems harmless to try it. – trashgod Aug 13 '13 at 01:44

2 Answers2

3

You have multiple options:

Thomas Mueller
  • 48,905
  • 14
  • 116
  • 132
  • Thanks! I didn't know about the serialized file locking mode. One advantage over automatic mixed mode would probably be that it should work even if the LAN clients all have their firewalls enabled. Or is that not a problem in automatic mixed mode? – Reto Höhener Aug 14 '13 at 06:29
  • Firewall settings are a problem with the automatic mixed mode. However, please note the 'serialized' mode is problematic as well as it relies on file locking, and it is experimental. I just heard this feature might go away in future versions of H2. – Thomas Mueller Aug 14 '13 at 06:58
  • Hm ok, so the 'serialized' mode is new and deprecated at the same time... Seems like the automatic mixed mode is my best bet, except for the firewall problematic. – Reto Höhener Aug 14 '13 at 19:18
  • 1
    Yes, the 'serialized' mode was a try, but it didn't work out all that great in practise. – Thomas Mueller Aug 15 '13 at 06:47
  • in auto_server mode , what would be the database url. If i want to connect from two or more different computers ? – Adi Jun 29 '17 at 10:09
  • @Adi just follow the links to the documentation in the answer. – Thomas Mueller Jun 29 '17 at 14:14
  • @ThomasMueller documentation says the url "jdbc:h2:/data/test;AUTO_SERVER=TRUE" . IF i use this in both computer . First start one application in Computer1 and start the same application in Computer2. How can computer2 would find my Computer1's "/data/test" .do i need to append Computer1's ip address before this given url? Please help. – Adi Jun 29 '17 at 14:35
  • @Adi please create a question. – Thomas Mueller Jun 29 '17 at 14:43
2
#Please find the full configuration: one should remember that if one has to run in server #and persistent mode with in spring boot application, the database file should be created #in advance. other wise create db file and place the location and start the h2 in server #mode

#Datasource Configuration
spring.datasource.driver-class-name=org.h2.Driver
spring.datasource.url=jdbc:h2:c:/data/studentdb;AUTO_SERVER=TRUE;AUTO_SERVER_PORT=8043;AUTO_RECONNECT=TRUE;DB_CLOSE_ON_EXIT=FALSE;DB_CLOSE_DELAY=-1;
spring.datasource.username=sa
spring.datasource.password=sa

#JPA Configuration
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.H2Dialect

#Connection Pool Configuration
spring.datasource.hikari.connection-timeout=20000
spring.datasource.hikari.minimum-idle=5
spring.datasource.hikari.maximum-pool-size=12
spring.datasource.hikari.idle-timeout=300000
spring.datasource.hikari.max-lifetime=1200000

#H2 Web Console
#spring.h2.console.enabled=true
spring.h2.console.path=/h2-console
spring.h2.console.settings.trace=false
spring.h2.console.settings.web-allow-others=true