Reputation: 37004
I get the following exception when connecting to the database:
org.h2.jdbc.JdbcSQLException: Connection is broken: "connect timed out" [90067-142]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:327)
at org.h2.message.DbException.get(DbException.java:156)
at org.h2.engine.SessionRemote.connectServer(SessionRemote.java:326)
at org.h2.engine.SessionRemote.connectEmbeddedOrServer(SessionRemote.java:248)
at org.h2.engine.SessionRemote.createSession(SessionRemote.java:214)
at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:111)
at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:95)
at org.h2.Driver.connect(Driver.java:73)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
................
Caused by: java.net.SocketTimeoutException: connect timed out
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:525)
at org.h2.util.NetUtils.createSocket(NetUtils.java:109)
at org.h2.util.NetUtils.createSocket(NetUtils.java:91)
at org.h2.engine.SessionRemote.initTransfer(SessionRemote.java:92)
at org.h2.engine.SessionRemote.connectServer(SessionRemote.java:322)
... 38 more
The connection string looks as follows:
jdbc:h2:C:\Users\Michael\.myadd\db;AUTO_SERVER=TRUE;CIPHER=AES
What can be the reason for such exception?
Thanks!
Upvotes: 3
Views: 13895
Reputation: 4553
It could happen, especially on Windows, when some process locks access to the db file. Easy way how to test it is to try to delete the file, if you can recreate it easily. Then you have to find the process and kill it.
Upvotes: 0
Reputation: 328
Restart your computer first (^_^)/ 再起動
I tried everything, but the only thing that seems to work is restarting my computer.
Here's a list of things that did NOT work:
I could even see the database working fine in the H2 Console, but eclipse would not connect to it until I restarted my computer.
I logged this error many times: "connection: org.h2.jdbc.JdbcSQLNonTransientConnectionException: Connection is broken: "java.net.SocketTimeoutException: Connect timed out: ..."
I restarted to connect to the database before lunch, and worked on my pc for an hour. It slept through lunch, then I had to restart my computer again to connect to the database in the afternoon.
Other comments are about MaxConnections
, but I am the only one using this database.
Upvotes: 0
Reputation: 1853
For h2 default connection pool size is 10 and login timeout is 30 sec, if we acquire 10 simultaneous connection for longer period then new request to acquire connection will be timed out. for my case found that connection was not getting closed due to bug in code. we can increase max connection count.
connectionPool.setMaxConnections(20);
but by default db manager is single threaded so more connection will not gain any performance.
Upvotes: 3
Reputation: 50147
I guess you read the docs about the automatic mixed mode? It's hard to say what the problem is, because for me it works. Could you post the content of the file C:\Users\Michael.myadd\db.lock.db ? For me it is (after connecting):
#FileLock
#Tue Dec 14 22:29:22 CET 2010
id=12ce6c9a16a912077e514cc6fff231e91b09d2dbe43
method=file
server=192.168.0.126\:52068
That means the database is open, and the client that opened it started a server on this IP address and port.
Upvotes: 1