I have a web app deployed on a Jboss EAP 6 that uses Hibernate to access a SQL Server database.
Every time I look for a specific register I get the error:
com.microsoft.sqlserver.jdbc.SQLServerException: The connection is closed
Search for any other register works fine. Restarting JBoss seems to solve the problem. Now I can get the register data without problem.
What could be causing the Exception for that register? Should I focus on the code? On the network? On the datasources definition? On the DB configuration?
There are many reasons, but very offten:
Look at your code, you maybe call close() method
Check out your connection string (NTLMv2?)
Check out MS SQL Server and their setting, DB servers looking for not active sessions and closing them.
Below reasons can be possible
Long query which is hanging up Sql Server.
Using Too much joins in query.
Tables contain more data and you have make the query in which join is not proper.
Related
i have a web based application which uses weblogic connection pooling while accessing oracle db. there is a procedure in which i must use db link to fetch and update remote table. but after a few call my service which triggers procedure call i got ORA-02020 – Too many database links in use error.
I think it causes from weblogic connection pool, it does not close session so db link is not closed and it reached max dblink count after a few try.
i've found http://dbtricks.com/?p=198 work around solution but it have not worked for me. i must use db link so what should i do? is there any solution for my case?
thanks.
I have a requirement that retrieving a connection times out within specified time from the connection pool if there is any problem in the network. This should be handled through a java application.
Basically, want to give timeout to datasource.getConnection() method.
So after some research, I found setLoginTimeout(int seconds) method of DataSource has this functionality in order to notify if a database connection can not be made within the specified seconds.
I applied this on OracleConnectionPoolDataSource which is working fine, but for the Derby client driver it's giving exception as,
org.apache.derby.jdbc.ClientDriver does not have any such attribute loginTimeout.
Looking for your kind responses, please do let me know if there any other way to achieve this as per my requirement or anything I need to add/missing or any information related to this.
Server - Resin 3.0
finally able to achieve this by using c3p0 connection pooling instead of using datasource for derby.C3P0 has checkoutTimeout property which exactly works as per this requirement.
It seems to me that we have some code that is not starting a transaction yet for read-only operations our queries via JPA/Hibernate as well as straight SQL seem to work. A hibernate/jpa session would have been opened by our framework but for a few spots in legacy code we found no transactions were being opened.
What seems to end up happening is that the code usually runs as long as it does not use EntityManager.persist and EntityManager.merge. However once in awhile (maybe 1/10) times the servlet container fails with this error...
Failed to load resource: the server responded with a status of 500 (org.hibernate.exception.JDBCConnectionException: The last packet successfully received from the server was 314,024,057 milliseconds ago. The last packet sent successfully to the server was 314,024,057 milliseconds ago. is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.)
As far as I can tell only the few spots in our application code that do not have transactions started before a query is made will have this problem. Does anybody else think it could be the non-transactional query running that causes this behaviour?
FYI here is our stack...
-Guice
-Guice-Persist
-Guice-Servlet
-MySql 5.1.63
-Hibernate/C3P0 4.1.4.Final
-Jetty
Yes, I think.
If you start a query without opening a transaction, this transaction will be opened automatically by the underlying layer. This connection, with an opened transaction, will be returned to the connection pool and given to another user, that will receive a connection to an already-opened transaction, and that could lead to inconsistent state.
Here in my company we had a lot of problems in the past with read-only non-transactional queries, and adjusted our framework to handle this.
Besides that, we talked to BoneCP developers and they accepted to develop a set of features to help handle this problem, like auto-rollback uncommitted transactions returned to the pool, and print a stack trace of what method forgot to commit the transaction.
This matter was discussed here:
http://jolbox.com/forum/viewtopic.php?f=3&t=98
I'm looking for a way to pass web-application transaction information on to the underlying database process. In my Java code I might have a transactional method ReservationService#search(), which runs one or several SQLs. On the DBMS I just see a SPID along with some locks. I'm looking for a way to add a tag "ReservationService#search" to the database process.
jTDS / Sybase ASE have an appName which can be passed in as a connection property. As we're using a connection pool, existing connections are re-used, but to my knowledge the appName is only read on establishing a new connection.
How can I re-set the appName on an already existing connection (without closing/opening)? Or, if that simply is impossible, are there any other ideas to get transactional context information from Java to the DBMS?
Tomcat Webapplication (Java 6)
C3P0 Connection Pool (only supports JDBC 3)
jTDS connecting to Sybase ASE 15
Thanks
Simon
Unfortunately not, it seems that you can only specify that in the URL parameters when you open up the connection but can't be altered afterwords.
You can aways pass in a SessionID of some kind from your Java/Tomecat to all your Sybase queries. For me, this was easy as I use stored procedures for all communications between my Java application and the SQL server. I based my SessionID in Java on the J2EE session.
We have an application using an Oracle StoredProc. When the stored proc is upgraded or recompiled from outside of our application, the database connections have to be closed and reopened. Otherwise we get an Oracle Exception ORA-20003.
Until now, we were using a WebLogic specific solution, where we were throwing a specific Exception and the Weblogic connection pool would mark the connection for eviction. We are now moving to Tomcat 6.
Is there a similar solution for Tomcat 6 ? Or even better, a generic solution ?
We could configure our connection pool with minIdle=0 and timeBetweenEvictionRunsMillis=some small number, but there still would be no garantie, only a mitigation of the problem.
Thanks for your help !
Can you come up with a SELECT statement that would validate whether the connection is up to date? If so, you could use it to configure the connection pool with validationQuery (potentially combined with connectionInitSqls).
Edit: Perhaps USER_OBJECTS.LAST_DDL_TIME can be of some help?