连接SQL Server 2008到Glassfish 3.1连接池的已关闭错误

时间:2012-08-08 00:16:42

标签: sql-server-2008 jpa glassfish connection-pooling

在我使用GlassFish 3.1连接池为SQL Server 2008创建的新“hello world”EJB / JPA应用程序中,我在第一次查询时总是出现“Connection closed”错误,并且在部署项目时经常(但并非总是)。我必须正确配置一些东西,我希望有人可以给我建议去哪看。

  • Windows 7 64位
  • Eclipse 4.2(Juno)64位
  • Java 1.6.0_33 64位
  • JPA Generic 2.0
  • EclipseLink 2.4.0 - Juno
  • 内部GlassFish 3.1.2.2
  • 用于SQL Server的Microsoft JDBC驱动程序4.0(sqljdbc4.jar)
  • Microsoft SQL Server 2008 R2(SQLEXPRESS)

我正在使用我使用GlassFish管理页面创建的默认设置的连接池(通过JTA)。 “平”成功了。这是来自domain.xml的池定义(我删除了密码):

<jdbc-connection-pool driver-classname="" datasource-classname="com.microsoft.sqlserver.jdbc.SQLServerConnectionPoolDataSource" res-type="javax.sql.ConnectionPoolDataSource" description="" name="DemoDatabase">
    <property name="User" value="demo"></property>
    <property name="DatabaseName" value="demo"></property>
    <property name="ApplicationName" value="Microsoft JDBC Driver for SQL Server"></property>
    <property name="LockTimeout" value="-1"></property>
    <property name="Password" value="******"></property>
    <property name="SendTimeAsDatetime" value="true"></property>
    <property name="PacketSize" value="8000"></property>
    <property name="SendStringParametersAsUnicode" value="true"></property>
    <property name="XopenStates" value="false"></property>
    <property name="TrustServerCertificate" value="false"></property>
    <property name="URL" value="jdbc:sqlserver://"></property>
    <property name="PortNumber" value="1433"></property>
    <property name="LoginTimeout" value="15"></property>
    <property name="ResponseBuffering" value="adaptive"></property>
    <property name="MultiSubnetFailover" value="false"></property>
    <property name="SelectMethod" value="direct"></property>
    <property name="LastUpdateCount" value="true"></property>
    <property name="WorkstationID" value="drizzle"></property>
    <property name="Encrypt" value="false"></property>
    <property name="ApplicationIntent" value="readwrite"></property>
</jdbc-connection-pool>
<jdbc-resource pool-name="DemoDatabase" description="" jndi-name="jdbc/DemoDatabase"></jdbc-resource>

的persistence.xml:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="DemoEJB">
    <jta-data-source>jdbc/DemoDatabase</jta-data-source>
</persistence-unit>
</persistence>

我还为MySQL设置了类似的GlassFish连接池。当我使用那个时,我没有得到“连接已关闭”错误。我认为这个问题出在我的SQL Server池配置中。

以下是GlassFish日志中的错误:

INFO: WEB0671: Loading application [DemoEAR#Demo.war] at [Demo]
INFO: DemoEAR was successfully deployed in 1,066 milliseconds.
INFO: RAR7114: Unable to get ClientInfo for connection 
INFO: RAR7115: Unable to set ClientInfo for connection
INFO: Communication failure detected when attempting to perform read query outside of a transaction. Attempting to retry query. Error was: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.microsoft.sqlserver.jdbc.SQLServerException: The connection is closed.
Error Code: 0
Call: SELECT ID, VAL FROM entity1 ORDER BY ID ASC
Query: ReadAllQuery(referenceClass=Entity1 sql="SELECT ID, VAL FROM entity1 ORDER BY ID ASC").
INFO: RAR7114: Unable to get ClientInfo for connection 
INFO: RAR7115: Unable to set ClientInfo for connection
INFO: Communication failure detected when attempting to perform read query outside of a transaction. Attempting to retry query. Error was: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.microsoft.sqlserver.jdbc.SQLServerException: The connection is closed.
Error Code: 0
Call: SELECT ID, VAL FROM entity1 ORDER BY ID ASC
Query: ReadAllQuery(referenceClass=Entity1 sql="SELECT ID, VAL FROM entity1 ORDER BY ID ASC").
INFO: RAR7114: Unable to get ClientInfo for connection 
INFO: RAR7115: Unable to set ClientInfo for connection
INFO: Communication failure detected when attempting to perform read query outside of a transaction. Attempting to retry query. Error was: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.microsoft.sqlserver.jdbc.SQLServerException: The connection is closed.
Error Code: 0
Call: SELECT ID, VAL FROM entity1 ORDER BY ID ASC
Query: ReadAllQuery(referenceClass=Entity1 sql="SELECT ID, VAL FROM entity1 ORDER BY ID ASC").
INFO: RAR7114: Unable to get ClientInfo for connection 
INFO: RAR7115: Unable to set ClientInfo for connection
INFO: Communication failure detected when attempting to perform read query outside of a transaction. Attempting to retry query. Error was: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.microsoft.sqlserver.jdbc.SQLServerException: The connection is closed.
Error Code: 0
Call: SELECT ID, VAL FROM entity1 ORDER BY ID ASC
Query: ReadAllQuery(referenceClass=Entity1 sql="SELECT ID, VAL FROM entity1 ORDER BY ID ASC").
INFO: RAR7114: Unable to get ClientInfo for connection 
INFO: RAR7115: Unable to set ClientInfo for connection
INFO: Communication failure detected when attempting to perform read query outside of a transaction. Attempting to retry query. Error was: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.microsoft.sqlserver.jdbc.SQLServerException: The connection is closed.
Error Code: 0
Call: SELECT ID, VAL FROM entity1 ORDER BY ID ASC
Query: ReadAllQuery(referenceClass=Entity1 sql="SELECT ID, VAL FROM entity1 ORDER BY ID ASC").
WARNING: Local Exception Stack: 
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.microsoft.sqlserver.jdbc.SQLServerException: The connection is closed.
Error Code: 0
Call: SELECT ID, VAL FROM entity1 ORDER BY ID ASC
Query: ReadAllQuery(referenceClass=Entity1 sql="SELECT ID, VAL FROM entity1 ORDER BY ID ASC")
at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:333)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.processExceptionForCommError(DatabaseAccessor.java:1494)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:636)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeCall(DatabaseAccessor.java:535)
at org.eclipse.persistence.internal.sessions.AbstractSession.basicExecuteCall(AbstractSession.java:1717)
at org.eclipse.persistence.sessions.server.ServerSession.executeCall(ServerSession.java:566)
at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:207)
at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:193)
at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeSelectCall(DatasourceCallQueryMechanism.java:264)
at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.selectAllRows(DatasourceCallQueryMechanism.java:646)
at org.eclipse.persistence.internal.queries.ExpressionQueryMechanism.selectAllRowsFromTable(ExpressionQueryMechanism.java:2611)
at org.eclipse.persistence.internal.queries.ExpressionQueryMechanism.selectAllRows(ExpressionQueryMechanism.java:2570)
at org.eclipse.persistence.queries.ReadAllQuery.executeObjectLevelReadQuery(ReadAllQuery.java:420)
at org.eclipse.persistence.queries.ObjectLevelReadQuery.executeDatabaseQuery(ObjectLevelReadQuery.java:1081)
at org.eclipse.persistence.queries.DatabaseQuery.execute(DatabaseQuery.java:844)
at org.eclipse.persistence.queries.ObjectLevelReadQuery.execute(ObjectLevelReadQuery.java:1040)
at org.eclipse.persistence.queries.ReadAllQuery.execute(ReadAllQuery.java:392)
at org.eclipse.persistence.queries.ObjectLevelReadQuery.executeInUnitOfWork(ObjectLevelReadQuery.java:1128)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.internalExecuteQuery(UnitOfWorkImpl.java:2871)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1516)
at org.eclipse.persistence.internal.sessions.AbstractSession.retryQuery(AbstractSession.java:1586)
at org.eclipse.persistence.sessions.server.ClientSession.retryQuery(ClientSession.java:593)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.retryQuery(UnitOfWorkImpl.java:5464)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1552)
at org.eclipse.persistence.internal.sessions.AbstractSession.retryQuery(AbstractSession.java:1586)
at org.eclipse.persistence.sessions.server.ClientSession.retryQuery(ClientSession.java:593)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.retryQuery(UnitOfWorkImpl.java:5464)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1552)
at org.eclipse.persistence.internal.sessions.AbstractSession.retryQuery(AbstractSession.java:1586)
at org.eclipse.persistence.sessions.server.ClientSession.retryQuery(ClientSession.java:593)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.retryQuery(UnitOfWorkImpl.java:5464)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1552)
at org.eclipse.persistence.internal.sessions.AbstractSession.retryQuery(AbstractSession.java:1586)
at org.eclipse.persistence.sessions.server.ClientSession.retryQuery(ClientSession.java:593)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.retryQuery(UnitOfWorkImpl.java:5464)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1552)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1498)
at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1463)
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.executeReadQuery(EJBQueryImpl.java:485)
at org.eclipse.persistence.internal.jpa.EJBQueryImpl.getResultList(EJBQueryImpl.java:742)
at com.centricsoftware.demo.module1.Module1.addEntity1(Module1.java:23)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.glassfish.ejb.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1052)
at org.glassfish.ejb.security.application.EJBSecurityManager.invoke(EJBSecurityManager.java:1124)
at com.sun.ejb.containers.BaseContainer.invokeBeanMethod(BaseContainer.java:5388)
at com.sun.ejb.EjbInvocation.invokeBeanMethod(EjbInvocation.java:619)
at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:800)
at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:571)
at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.doAround(SystemInterceptorProxy.java:162)
at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.aroundInvoke(SystemInterceptorProxy.java:144)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:861)
at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:800)
at com.sun.ejb.containers.interceptors.InterceptorManager.intercept(InterceptorManager.java:370)
at com.sun.ejb.containers.BaseContainer.__intercept(BaseContainer.java:5360)
at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:5348)
at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:214)
at com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:89)
at $Proxy216.addEntity1(Unknown Source)
at com.centricsoftware.demo.module1.__EJB31_Generated__Module1__Intf____Bean__.addEntity1(Unknown Source)
at com.centricsoftware.demo.server.GreetingServiceImpl.greetServer(GreetingServiceImpl.java:31)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:569)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:208)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.processPost(RemoteServiceServlet.java:248)
at com.google.gwt.user.server.rpc.AbstractRemoteServiceServlet.doPost(AbstractRemoteServiceServlet.java:62)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:688)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:770)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1550)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
at java.lang.Thread.run(Thread.java:662)
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: The connection is closed.
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(SQLServerException.java:190)
at com.microsoft.sqlserver.jdbc.SQLServerConnectionPoolProxy.checkClosed(SQLServerConnectionPoolProxy.java:55)
at com.microsoft.sqlserver.jdbc.SQLServerConnectionPoolProxy.prepareStatement(SQLServerConnectionPoolProxy.java:207)
at com.sun.gjc.spi.base.ConnectionHolder.prepareStatement(ConnectionHolder.java:562)
at com.sun.gjc.spi.jdbc40.ConnectionWrapper40.prepareCachedStatement(ConnectionWrapper40.java:255)
at com.sun.gjc.spi.jdbc40.ConnectionWrapper40.prepareCachedStatement(ConnectionWrapper40.java:52)
at com.sun.gjc.spi.ManagedConnection.prepareCachedStatement(ManagedConnection.java:993)
at com.sun.gjc.spi.jdbc40.ConnectionWrapper40.prepareStatement(ConnectionWrapper40.java:173)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.prepareStatement(DatabaseAccessor.java:1474)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.prepareStatement(DatabaseAccessor.java:1423)
at org.eclipse.persistence.internal.databaseaccess.DatabaseCall.prepareStatement(DatabaseCall.java:697)
at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:585)
... 98 more

2 个答案:

答案 0 :(得分:0)

您的数据库服务器是否正在运行?

可能它与您的LoginTimeout属性有关,您的登录可能需要更长时间。尝试从连接池配置中删除除必需属性之外的所有属性。

它也可能是防火墙,网络或数据库问题导致您的连接超时。

您还可以在连接池中启用连接测试,以在返回之前验证连接。

您也可以使用EclipseLink连接池,或尝试查看是否遇到同样的问题。

另外,请包含您的persistence.xml。

答案 1 :(得分:0)

您必须在glassfish服务器中添加.jar jdbc sqlserver驱动程序,如下所示:{installationPth} \ glassfish4 \ glassfish \ domains \ domain1 \ lib \ ext

享受Kahoo:

(_ /) (=&#39;&#39; =) (&#34;)_(&#34)