问题
I use H2 Database as DBMS from a remote computer,so I enabled remote access from a browser as follows:
webAllowOthers=true
but when i try to connect to the server from my java application i get this error from H2:
remote connections to this server are not allowed
screenshot:
And also already looking into the code Analyzer with (Error Code: 90117):
REMOTE_CONNECTION_NOT_ALLOWED = 90117
The error with code 90117 is thrown when trying to connect to a TCP server from another machine, if remote connections are not allowed. To allow remote connections, start the TCP server using the option -tcpAllowOthers as in:
java org.h2.tools.Server -tcp -tcpAllowOthers
Or, when starting the server from an application, use: Server server = Server.createTcpServer("-tcpAllowOthers"); server.start();
I do not understand how to activate the tcpAllowOthers, it does not exist in .h2.server.properties ?
回答1:
There are two different server:
- the Web Console server that is used to run the H2 Console tool (the GUI tool). It can be accessed by a browser only.
- the TCP server that allows to connect an application that uses JDBC, when using the client/server mode (
jdbc:h2:tcp://localhost/~/test)
The file .h2.server.properties is only used for the Web Console server. It only supports webAllowOthers=true. This file is not used by the TCP server.
To enable remote access to the TCP server, you need to start the TCP server using the option -tcpAllowOthers. To start both the Web Console server (the H2 Console tool) and the TCP server with remote connections enabled, you would need to use:
java -jar h2*.jar -web -webAllowOthers -tcp -tcpAllowOthers -browser
(this also starts a browser)
来源:https://stackoverflow.com/questions/9838041/connection-has-a-remote-database