Setting up an H2 server (Windows)

You can set up your H2 database as a server for multiple users. These instructions are for the Windows platform: for other platforms please contact StrataData or look on the H2 site for advice.

You can run your H2 database as a standalone database or as a served database without changing the database file itself. Unlike the more heavyweight database systems like SQL Server or Oracle, this means that you can take a copy of the database file and use it as a standalone database if you need to use it outside the server. When you use the database as a server, you are no longer accessing the database through file reading/sharing, but you are communicating with a server process over TCP. If you have more than one simultaneous user of your database, you must use a server process to avoid file locking issues.

The H2 server is simple to set up and can be started when the server machine is started. To install and configure the H2 server you must have Administrator privilege on the server machine. The server machine is most typically the office file server, but could in fact be any machine on the network. The most important factor is that it is available any time a user on the network needs to use the database.

Important: Wherever your database is located, it is vital that it is included in regular (nightly) backup schedules.

Download h2 system

Download the H2 bundle. This should be avilable from the H2 downloads page. Do not install the latest version. The last stable version, which is 1.3.176, seems to be missing from the H2 dsownload, but you can get a copy here. Download the Windows installer package. It is recommended that you do not install to "C:\Program Files (x86)\" as this might cause problems when you run the scripts to install the service. Install instead to a dedicated folder, say, D:\apps\H2. You should see a docs folder with the documentation, and \bin and \service folders.

You will also need a version of Java installed on your file server, so that you can run the Java command.

All the information you need is in the h2.pdf file in the \docs folder, but here is a simple summary of the most important commands:

Starting and stopping the server

To test the procedure before installing the service, you can start the H2 server manually. Go into the \bin folder. From the command line using the following command:

java -cp h2.jar org.h2.tools.Server -tcpAllowOthers -pgAllowOthers

You will need to have a valid Java JRE on your path so that it can find the java command. The flag -tcpAllowOthers will allow connections to the server from other machines on the network. Without this flag, you would only be able to connect from the local machine. This command will also start the console app in your web browser. If you need to start the console app independently of this, use the h2w.bat script in the \bin folder.

The -pgAllowOthers will only be required if you need to use the legacy charts application which uses the ODBC PostgreSQL driver.

The console

If the console does not start in the browser, you can connect to it by using the following url:

http://localhost:8082

You can use the console to explore the database structure

To connect to the database via the console, or to test the connection, in the jdbc URL field you must include the path to the database file. For instance, if your database file was called sbugs2-1_corporate.h2.db and in the data StrataBugs folder on drive D, the JDBC setting would be:

jdbc:h2:tcp://localhost/D:\StrataBugs2-1\data\sbugs2-1_corporate

The user name to use is: SBUGS_USER with the password "system".

Connecting to the database from a client

From a client machine, in the StrataBugs connection settings, select the following options:

jdbc: type h2

Server name or IP: tcp://server:9092/D:\StrataBugs2-1\data\sbugs2-1_corporate

*where server is the name of your database server.

Ensure that the Autoserver mode(h2) flag is OFF.

Installing the Windows service

When you install the H2 service in Windows, the database server can be started when the server machine is booted, so that it is always available. Go to the \service folder. Edit the file wrapper.conf and insert the following line:

# Application parameters. Add parameters as needed starting from 1
wrapper.app.parameter.1=org.h2.tools.Server
wrapper.app.parameter.2=-tcpAllowOthers
wrapper.app.parameter.3=-pgAllowOthers

Run the batch scripts to install and start the service, as Administrator (right-click and run as Administrator). To troubleshoot, refer to the wrapper.log file created.

You can modify the service parameters by finding the H2 server in the list of Services under Computer : Manage and opening the Properties. Make sure that the service is set to Automatic, or Automatic (delayed start).