0 Replies Latest reply on Oct 16, 2011 10:19 AM by Sven Plath

    MSSQL Driver getConnection() throwing Exceptions

    Sven Plath Newbie

      Hi there,

       

      I started developing with AS7 and ran into a few problems regarding the connectivity between my SQL Server 2008 R2 Standard Edition (running in a virtual machine for testing) and my Webapp.

       

      I installed the driver as a module (module.xml) according to http://community.jboss.org/message/617978 :

       

      <module xmlns="urn:jboss:module:1.0" name="com.microsoft.sqlserver.jdbc">
           <resources>
                <resource-root path="sqljdbc4.jar"/>
           </resources>
           <dependencies>
                <module name="javax.api"/>
                <module name="javax.transaction.api"/>
           </dependencies>
      </module>
      

       

      Furthermore i created the following datasource (standalone.xml):

       

      <datasources>
           <datasource jndi-name="java:/datasources/ResourceDS" pool-name="SQL" enabled="true" jta="true" use-java-context="false">
           <connection-url>
                jdbc:sqlserver://192.168.56.101\TEST
           </connection-url>
           <driver>sqlserver</driver>
           <security>
                <user-name>sa</user-name>
                <password>test</password>
           </security>
      </datasource>
      <drivers>
           <driver name="sqlserver" module="com.microsoft.sqlserver.jdbc"/>
      </drivers>
      

       

      My Application uses the following function to create a connection:

       

      private void testConnection() {
           try {
                InitialContext initialContext = new InitialContext();
                DataSource dataSource;
                
                dataSource = (DataSource) initialContext.lookup("java:/datasources/ResourceDS");
                Connection con = dataSource.getConnection();
           } catch (Exception e) {
                e.printStackTrace();
           }
      }
      

       

      And this leads to this Exception:

       

      15:58:30,458 ERROR [stderr] (http--127.0.0.1-8080-2) java.sql.SQLException: javax.resource.ResourceException: IJ000453: Unable to get managed connection for java:/datasources/ResourceDS
      15:58:30,459 ERROR [stderr] (http--127.0.0.1-8080-2)           at org.jboss.jca.adapters.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:137)
      15:58:30,459 ERROR [stderr] (http--127.0.0.1-8080-2)           at demo.User.testConnection(User.java:60)
      15:58:30,460 ERROR [stderr] (http--127.0.0.1-8080-2)           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      15:58:30,460 ERROR [stderr] (http--127.0.0.1-8080-2)           at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      15:58:30,460 ERROR [stderr] (http--127.0.0.1-8080-2)           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      15:58:30,460 ERROR [stderr] (http--127.0.0.1-8080-2)           at java.lang.reflect.Method.invoke(Method.java:597)
      15:58:30,460 ERROR [stderr] (http--127.0.0.1-8080-2)           at org.apache.el.parser.AstValue.invoke(AstValue.java:196)
      15:58:30,461 ERROR [stderr] (http--127.0.0.1-8080-2)           at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
      15:58:30,461 ERROR [stderr] (http--127.0.0.1-8080-2)           at com.sun.faces.facelets.el.ContextualCompositeMethodExpression.invoke(ContextualCompositeMethodExpression.java:177)
      15:58:30,461 ERROR [stderr] (http--127.0.0.1-8080-2)           at com.sun.faces.facelets.tag.TagAttributeImpl$AttributeLookupMethodExpression.invoke(TagAttributeImpl.java:450)
      15:58:30,461 ERROR [stderr] (http--127.0.0.1-8080-2)           at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88)
      15:58:30,461 ERROR [stderr] (http--127.0.0.1-8080-2)           at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
      15:58:30,462 ERROR [stderr] (http--127.0.0.1-8080-2)           at javax.faces.component.UICommand.broadcast(UICommand.java:315)
      15:58:30,462 ERROR [stderr] (http--127.0.0.1-8080-2)           at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794)
      15:58:30,462 ERROR [stderr] (http--127.0.0.1-8080-2)           at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259)
      15:58:30,463 ERROR [stderr] (http--127.0.0.1-8080-2)           at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
      15:58:30,463 ERROR [stderr] (http--127.0.0.1-8080-2)           at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
      15:58:30,463 ERROR [stderr] (http--127.0.0.1-8080-2)           at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
      15:58:30,463 ERROR [stderr] (http--127.0.0.1-8080-2)           at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
      15:58:30,464 ERROR [stderr] (http--127.0.0.1-8080-2)           at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329)
      15:58:30,464 ERROR [stderr] (http--127.0.0.1-8080-2)           at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)
      15:58:30,464 ERROR [stderr] (http--127.0.0.1-8080-2)           at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275)
      15:58:30,464 ERROR [stderr] (http--127.0.0.1-8080-2)           at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161)
      15:58:30,472 ERROR [stderr] (http--127.0.0.1-8080-2)           at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:139)
      15:58:30,472 ERROR [stderr] (http--127.0.0.1-8080-2)           at org.jboss.as.web.NamingValve.invoke(NamingValve.java:57)
      15:58:30,472 ERROR [stderr] (http--127.0.0.1-8080-2)           at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:154)
      15:58:30,472 ERROR [stderr] (http--127.0.0.1-8080-2)           at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
      15:58:30,473 ERROR [stderr] (http--127.0.0.1-8080-2)           at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
      15:58:30,473 ERROR [stderr] (http--127.0.0.1-8080-2)           at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:362)
      15:58:30,473 ERROR [stderr] (http--127.0.0.1-8080-2)           at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877)
      15:58:30,473 ERROR [stderr] (http--127.0.0.1-8080-2)           at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:667)
      15:58:30,474 ERROR [stderr] (http--127.0.0.1-8080-2)           at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:952)
      15:58:30,474 ERROR [stderr] (http--127.0.0.1-8080-2)           at java.lang.Thread.run(Thread.java:662)
      15:58:30,475 ERROR [stderr] (http--127.0.0.1-8080-2) Caused by: javax.resource.ResourceException: IJ000453: Unable to get managed connection for java:/datasources/ResourceDS
      15:58:30,475 ERROR [stderr] (http--127.0.0.1-8080-2)           at org.jboss.jca.core.connectionmanager.AbstractConnectionManager.getManagedConnection(AbstractConnectionManager.java:394)
      15:58:30,475 ERROR [stderr] (http--127.0.0.1-8080-2)           at org.jboss.jca.core.connectionmanager.tx.TxConnectionManagerImpl.getManagedConnection(TxConnectionManagerImpl.java:367)
      15:58:30,475 ERROR [stderr] (http--127.0.0.1-8080-2)           at org.jboss.jca.core.connectionmanager.AbstractConnectionManager.allocateConnection(AbstractConnectionManager.java:467)
      15:58:30,475 ERROR [stderr] (http--127.0.0.1-8080-2)           at org.jboss.jca.adapters.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:129)
      15:58:30,476 ERROR [stderr] (http--127.0.0.1-8080-2)           ... 33 more
      15:58:30,476 ERROR [stderr] (http--127.0.0.1-8080-2) Caused by: javax.resource.ResourceException: IJ000658: Unexpected throwable while trying to create a connection: null
      15:58:30,476 ERROR [stderr] (http--127.0.0.1-8080-2)           at org.jboss.jca.core.connectionmanager.pool.mcp.SemaphoreArrayListManagedConnectionPool.getConnection(SemaphoreArrayListManagedConnectionPool.java:349)
      15:58:30,476 ERROR [stderr] (http--127.0.0.1-8080-2)           at org.jboss.jca.core.connectionmanager.pool.AbstractPool.getSimpleConnection(AbstractPool.java:392)
      15:58:30,477 ERROR [stderr] (http--127.0.0.1-8080-2)           at org.jboss.jca.core.connectionmanager.pool.AbstractPool.getConnection(AbstractPool.java:357)
      15:58:30,477 ERROR [stderr] (http--127.0.0.1-8080-2)           at org.jboss.jca.core.connectionmanager.AbstractConnectionManager.getManagedConnection(AbstractConnectionManager.java:351)
      15:58:30,477 ERROR [stderr] (http--127.0.0.1-8080-2)           ... 36 more
      15:58:30,477 ERROR [stderr] (http--127.0.0.1-8080-2) Caused by: javax.resource.ResourceException: Could not create connection
      15:58:30,477 ERROR [stderr] (http--127.0.0.1-8080-2)           at org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory.getLocalManagedConnection(LocalManagedConnectionFactory.java:277)
      15:58:30,477 ERROR [stderr] (http--127.0.0.1-8080-2)           at org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory.createManagedConnection(LocalManagedConnectionFactory.java:235)
      15:58:30,478 ERROR [stderr] (http--127.0.0.1-8080-2)           at org.jboss.jca.core.connectionmanager.pool.mcp.SemaphoreArrayListManagedConnectionPool.createConnectionEventListener(SemaphoreArrayListManagedConnectionPool.java:706)
      15:58:30,478 ERROR [stderr] (http--127.0.0.1-8080-2)           at org.jboss.jca.core.connectionmanager.pool.mcp.SemaphoreArrayListManagedConnectionPool.getConnection(SemaphoreArrayListManagedConnectionPool.java:321)
      15:58:30,478 ERROR [stderr] (http--127.0.0.1-8080-2)           ... 39 more
      15:58:30,478 ERROR [stderr] (http--127.0.0.1-8080-2) Caused by: java.lang.NoClassDefFoundError: Could not initialize class javax.crypto.SunJCE_b
      15:58:30,478 ERROR [stderr] (http--127.0.0.1-8080-2)           at javax.crypto.KeyGenerator.a(DashoA13*..)
      15:58:30,478 ERROR [stderr] (http--127.0.0.1-8080-2)           at javax.crypto.KeyGenerator.<init>(DashoA13*..)
      15:58:30,479 ERROR [stderr] (http--127.0.0.1-8080-2)           at javax.crypto.KeyGenerator.getInstance(DashoA13*..)
      15:58:30,479 ERROR [stderr] (http--127.0.0.1-8080-2)           at com.sun.net.ssl.internal.ssl.JsseJce.getKeyGenerator(JsseJce.java:223)
      15:58:30,479 ERROR [stderr] (http--127.0.0.1-8080-2)           at com.sun.net.ssl.internal.ssl.RSAClientKeyExchange.<init>(RSAClientKeyExchange.java:89)
      15:58:30,479 ERROR [stderr] (http--127.0.0.1-8080-2)           at com.sun.net.ssl.internal.ssl.ClientHandshaker.serverHelloDone(ClientHandshaker.java:744)
      15:58:30,479 ERROR [stderr] (http--127.0.0.1-8080-2)           at com.sun.net.ssl.internal.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:238)
      15:58:30,479 ERROR [stderr] (http--127.0.0.1-8080-2)           at com.sun.net.ssl.internal.ssl.Handshaker.processLoop(Handshaker.java:593)
      15:58:30,480 ERROR [stderr] (http--127.0.0.1-8080-2)           at com.sun.net.ssl.internal.ssl.Handshaker.process_record(Handshaker.java:529)
      15:58:30,480 ERROR [stderr] (http--127.0.0.1-8080-2)           at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:893)
      15:58:30,480 ERROR [stderr] (http--127.0.0.1-8080-2)           at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1138)
      15:58:30,480 ERROR [stderr] (http--127.0.0.1-8080-2)           at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1165)
      15:58:30,480 ERROR [stderr] (http--127.0.0.1-8080-2)           at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1149)
      15:58:30,480 ERROR [stderr] (http--127.0.0.1-8080-2)           at com.microsoft.sqlserver.jdbc.TDSChannel.enableSSL(IOBuffer.java:1483)
      15:58:30,481 ERROR [stderr] (http--127.0.0.1-8080-2)           at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1042)
      15:58:30,481 ERROR [stderr] (http--127.0.0.1-8080-2)           at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:817)
      15:58:30,481 ERROR [stderr] (http--127.0.0.1-8080-2)           at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:700)
      15:58:30,481 ERROR [stderr] (http--127.0.0.1-8080-2)           at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:842)
      15:58:30,481 ERROR [stderr] (http--127.0.0.1-8080-2)           at org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory.getLocalManagedConnection(LocalManagedConnectionFactory.java:249)
      15:58:30,481 ERROR [stderr] (http--127.0.0.1-8080-2)           ... 42 more
      
      

       

      I am kind of new to this whole database / datasource / connectivity stuff, any help is appreciated.

       

      For testing, I played around with the datasource JNDI Name (according to http://blogs.oracle.com/kensaks/entry/application_specified_portable_jndi_names ) as well as trying different connectionURLs. But since the datasource is created and the connection fails, I assume the JNDI name should not be the problem. The database VM is accessible from my machine, pinging is working, no firewalls in between.

       

      Thanks in advance.

       

      Regards,

      Sven Plath