SQL Server Login failed for user Jboss AS7 - sql-server

I am attempting to set up multiple datasources in my standalone.xml file. I have a connection to DB2 up and working fine. I am having trouble getting the SQL Server connection to work.
From standalone.xml:
<datasource jndi-name="java:/jdbc/syteline" pool-name="SYTELINEMSSDS" enabled="true" use-java-context="true" spy="true">
<connection-url>jdbc:sqlserver://SLSQL:1433;databaseName=npsl_pilot_app;</connection-url>
<driver-class>com.microsoft.sqlserver.jdbc.SQLServerDriver</driver-class>
<driver>sqljdbc4.jar</driver>
<pool>
<min-pool-size>5</min-pool-size>
<max-pool-size>10</max-pool-size>
<prefill>true</prefill>
<use-strict-min>false</use-strict-min>
</pool>
<security>
<user-name>myUser</user-name>
<password>myPass</password>
</security>
<timeout>
<idle-timeout-minutes>15</idle-timeout-minutes>
</timeout>
</datasource>
I have the sqljdbc4.jar deployed in my standalone\deployments directory and it is deploying. I have tested the connection URL and credentials by copy/pasting it into my application and creating a JDBC connection within my code. That connection works properly. Setting the connection up as a datasource in standalone.xml gives me the following:
15:20:00,326 INFO [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-15) JBAS010400: Bound data source [java:/jdbc/syteline]
15:20:00,684 WARN [org.jboss.jca.core.connectionmanager.pool.strategy.OnePool] (JCA PoolFiller) IJ000610: Unable to fill pool: javax.resource.ResourceException: Could not create connection
at org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory.getLocalManagedConnection(LocalManagedConnectionFactory.java:277)
at org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory.createManagedConnection(LocalManagedConnectionFactory.java:235)
at org.jboss.jca.core.connectionmanager.pool.mcp.SemaphoreArrayListManagedConnectionPool.createConnectionEventListener(SemaphoreArrayListManagedConnectionPool.java:758) [ironjacamar-core-impl-1.0.7.Final.jar:1.0.7.Final]
at org.jboss.jca.core.connectionmanager.pool.mcp.SemaphoreArrayListManagedConnectionPool.fillToMin(SemaphoreArrayListManagedConnectionPool.java:703) [ironjacamar-core-impl-1.0.7.Final.jar:1.0.7.Final]
at org.jboss.jca.core.connectionmanager.pool.mcp.PoolFiller.run(PoolFiller.java:97) [ironjacamar-core-impl-1.0.7.Final.jar:1.0.7.Final]
at java.lang.Thread.run(Thread.java:662) [rt.jar:1.6.0_23]
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user 'dna'. ClientConnectionId:4e4e0e7f-3e23-4a13-9c49-37e33aeb4613
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:216)
at com.microsoft.sqlserver.jdbc.TDSTokenHandler.onEOF(tdsparser.java:254)
at com.microsoft.sqlserver.jdbc.TDSParser.parse(tdsparser.java:84)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.sendLogon(SQLServerConnection.java:2908)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.logon(SQLServerConnection.java:2234)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.access$000(SQLServerConnection.java:41)
at com.microsoft.sqlserver.jdbc.SQLServerConnection$LogonCommand.doExecute(SQLServerConnection.java:2220)
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:5696)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1715)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1326)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:991)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:827)
at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:1012)
at org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory.getLocalManagedConnection(LocalManagedConnectionFactory.java:249)
... 5 more
15:20:01,385 WARN [org.jboss.as.server.deployment] (MSC service thread 1-14) Class Path entry jcifs.jar in "/C:/jbossdir/jboss7/standalone/deployments/speed2.war/WEB-INF/lib/jtds-1.2.5.jar" does not point to a valid jar for a Class-Path reference.
I have not been able to figure out the Login Failed message.

Is the JBoss server on the same computer as the test application that can connect properly?

Just as a followup, I gave up on the Microsoft driver and used JTDS instead. Works fine.

Related

KeyCloak is not able to communicate with DB all of sudden : throwing exception

KeyCloak is not able to communicate with our DB and leaving below error message. However, we got rid of this by doing restart. But seems it is occurring often. Suggestions/Solutions would be better ...
Error Snippet:
(Timer-2) SQL Error: 17008, SQLState: 08003 2019-11-25 23:35:21,389
ERROR [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (Timer-2)
Closed Connection 2019-11-25 23:35:21,389 ERROR
[org.keycloak.services] (Timer-2) KC-SERVICES0089: Failed to run
scheduled task ClearExpiredEvents:
javax.persistence.PersistenceException:
org.hibernate.exception.JDBCConnectionException: could not prepare
statement
at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1692)
at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1602)
at org.hibernate.jpa.internal.QueryImpl.getResultList(QueryImpl.java:492)
at org.keycloak.models.jpa.JpaRealmProvider.getRealms(JpaRealmProvider.java:99)
at org.keycloak.models.cache.infinispan.RealmCacheSession.getRealms(RealmCacheSession.java:459)
at org.keycloak.services.scheduled.ClearExpiredEvents.run(ClearExpiredEvents.java:34)
at org.keycloak.services.scheduled.ClusterAwareScheduledTaskRunner$1.call(ClusterAwareScheduledTaskRunner.java:56)
at org.keycloak.services.scheduled.ClusterAwareScheduledTaskRunner$1.call(ClusterAwareScheduledTaskRunner.java:52)
at org.keycloak.cluster.infinispan.InfinispanClusterProvider.executeIfNotExecuted(InfinispanClusterProvider.java:78)
at org.keycloak.services.scheduled.ClusterAwareScheduledTaskRunner.runTask(ClusterAwareScheduledTaskRunner.java:52)
at org.keycloak.services.scheduled.ScheduledTaskRunner.run(ScheduledTaskRunner.java:45)
at org.keycloak.timer.basic.BasicTimerProvider$1.run(BasicTimerProvider.java:51)
at java.util.TimerThread.mainLoop(Timer.java:555)
at java.util.TimerThread.run(Timer.java:505) Caused by: org.hibernate.exception.JDBCConnectionException: could not prepare
statement
Thanks Everyone for spending time on this thread. However, this issue has been resolved .. Seems there was issue with keycloak and the latest patch update resolved it.
This connection pool change will work.
<datasource jndi-name="java:jboss/datasources/KeycloakDS" pool-name="KeycloakDS" enabled="true" use-java-context="true">
<connection-url>jdbc:postgresql://host.docker.internal:5432/postgres_db</connection-url>
<driver>postgresql</driver>
<pool>
<max-pool-size>100</max-pool-size>
</pool>
<security>
<user-name>postgres_user</user-name>
<password>postgres_password</password>
</security>
<validation>
<valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLValidConnectionChecker"></valid-connection-checker>
<background-validation>true</background-validation>
<background-validation-millis>120000</background-validation-millis>
</validation>
</datasource>

Jackrabbit MSSQL database repository

Any specific reason why abruptly connection to MSSQL server is lost. I am running web application on the same machine so network connectivity issues are out of question. My application uses Jackrabbit configured to store content with MSSQL. Application is running on Wildfly v9 with JAVA_HOME set to jdk1.8 and I have verified that wildfly is picking it up as well. Also, sqljdbc4-3.0.jar is available to wildfly modules with proper driver configuration in standalone. I am baffled as to why jdk7 adapter would be called to manage connection. However, interesting observation is that this does not occur with Wildfly 10.
standalone.xml
<driver name="sqlserver" module="com.microsoft.sqlserver">
<driver-class>com.microsoft.sqlserver.jdbc.SQLServerDriver</driver-class>
<xa-datasource-class>com.microsoft.sqlserver.jdbc.SQLServerXADataSource</xa-datasource-class>
</driver>
exception:
ERROR 21-07 16:41:13,636 (DbUtility.java:logException:92) failed to close ResultSet
ERROR 21-07 16:41:13,637 (DbUtility.java:logException:94) Reason: IJ031040: Connection is not associated with a managed connection: org.jboss.jca.adapters.jdbc.jdk7.WrappedConnectionJDK7#386eff84
ERROR 21-07 16:41:13,639 (DbUtility.java:logException:95) State/Code: null/0

SQL Server using Windows Authentication in Wildfly as service

I'm configuring a datasource to use windows authentication with SQL Server.
I put the DLL sqljdbc_auth.dll in C:\Program Files\XXXX\wildfly-10.1.0.Final\bin
Stating Wildfly using standalone.bat works fine.
But using windows service I got this error:
Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Cannot open database "Scope_Build36" requested by the login. The login failed. ClientConnectionId:831c2f7f-4352-4467-b54f-a6eb1369d6e9
at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:217)
at com.microsoft.sqlserver.jdbc.TDSTokenHandler.onEOF(tdsparser.java:251)
at com.microsoft.sqlserver.jdbc.TDSParser.parse(tdsparser.java:81)
at com.microsoft.sqlserver.jdbc.SQLServerConnection$1LogonProcessor.complete(SQLServerConnection.java:2825)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.sendLogon(SQLServerConnection.java:3079)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.logon(SQLServerConnection.java:2360)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.access$100(SQLServerConnection.java:43)
at com.microsoft.sqlserver.jdbc.SQLServerConnection$LogonCommand.doExecute(SQLServerConnection.java:2346)
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:6276)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1793)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1404)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:1068)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectInternal(SQLServerConnection.java:904)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:451)
at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:1014)
at org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory.createLocalManagedConnection(LocalManagedConnectionFactory.java:321)
... 44 more
DataSource configuration:
<datasource jta="true" jndi-name="java:/datasources/PortalScopeWeb_Scope" pool-name="PortalScopeWeb_Scope" enabled="true" use-ccm="true">
<connection-url>jdbc:sqlserver://RI001421D\SQLEXPRESS:1433;databasename=Scope_Build36;integratedSecurity=true</connection-url>
<driver>sqlServer</driver>
<security>
<security-domain>securityDomainPortalScopeWeb_Scope</security-domain>
</security>
<validation>
<check-valid-connection-sql>SELECT 1</check-valid-connection-sql>
<validate-on-match>true</validate-on-match>
<background-validation>false</background-validation>
</validation>
</datasource>
Putting DDL in folder C:\Program Files\XXXX\wildfly-10.1.0.Final\bin\service\amd64 don't solved the problem.
you can use a .udl file to test and verify your connection.
In you desktop create a new .txt file, and rename it like "test.udl". Now, open it, and you can configure and test your connection. When you have the connection ready, you can open the .udl file with notepad and copy connection string.
here you have a reference: udl reference
hope this help!

Connection problems MS SQL 2008 in EAP 6.4

I am new to JBoss EAP and using 6.4 version . Earlier I have been using Tomcat 7.39. I like to shift from tomcat to JBOSS EAP 6.4. From some posts in stack overflow and JBOSS EAP , I some how configure MS SQL 2008 in JBOSS EAP but it is not working .
Standalone.xml File
<subsystem xmlns="urn:jboss:domain:datasources:1.2">
<datasources>
<datasource jndi-name="java:jboss/datasources/TMS" pool-name="TMS" enabled="true" use-java-context="true">
<connection-url>jdbc:sqlserver://localhost:1433;databaseName=TMS;integratedSecurity=false;</connection-url>
<driver>sqlserver</driver>
<security>
<user-name>sa</user-name>
<password>1234</password>
</security>
</datasource>
<drivers>
<driver name="sqlserver" module="com.microsoft.sqlserver">
<xa-datasource-class>com.microsoft.sqlserver.jdbc.SQLServerXADataSource</xa-datasource-class>
</driver>
</drivers>
</datasources>
</subsystem>
Earlier as I do not have any pool-name , I have deleted this attribute from datasource tag. Now I have just kept the pool name as database name though I do not have any pool name yet. Should I have to create pool-name and how could I do that ?
I Created (com\microsoft\sqlserver\main) this folder structure in *EAP_HOME\modules* and Then there I kept sqljdbc4.jar and module.xml. I am using windows 7, 32 bit machine. Below is the code snippet of module.xml:-
<module xmlns="urn:jboss:module:1.1" name="com.microsoft.sqlserver">
<resources>
<resource-root path="sqljdbc4.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
</dependencies>
And I am getting this error ERROR com.microsoft.sqlserver.jdbc.SQLServerDriver from [Module "deployment.TSM_UI.war:main" from Service Module Loader]
I am thinking that it might be due to my pool name.Any suggestion. Thanks in Advance
The Error-Message doesn't look complete. I guess it is "ERROR ClassNotFoundEcxeption: Could not load class com.microsoft.sqlserver.jdbc.SQLServerDriver from [Module "deployment.TSM_UI.war:main" from Service Module Loader]" ?
Then you try to load the driver directly from within your deployment, but you should use a JNDI-lookup to get the connection from the datasource you created.
Search your deployment (TSM_UI.war) whether you have any references to com.microsoft.sqlserver.jdbc.SQLServerDriver within your deployment and remove it.

SQL Server connection in Wildfly using JTDS driver

What is the correct way to setup a SQL Server datasource on Widlfly?
I need to access a SQL Server database from my web application which runs on Wildfly.
I have setup the datasource as follows:
<datasource jta="false" jndi-name="java:jboss/db" pool-name="db" enabled="true" use-ccm="false">
<connection-url>jdbc:jtds:sqlserver://IP_ADDRESS;instance=SQLEXPRESS;DatabaseName=DB</connection-url>
<driver-class>net.sourceforge.jtds.jdbc.Driver</driver-class>
<driver>jtds-1.3.1.jar</driver>
</datasource>
This works fine except that when the SQL Server is restarted, the connection is lost and the datasource doesn't manage to recreate one. So I get errors like:
Invalid state, the Connection object is closed.
This post suggests adding some validation, so I did this:
<validation>
<check-valid-connection-sql>SELECT 1</check-valid-connection-sql>
<validate-on-match>false</validate-on-match>
<background-validation>false</background-validation>
</validation>
But that does not solve the problem and I still get the same "connection closed" error from time to time.
This other post suggests using a DataSource instead of a Driver, so I have added this to my configuration:
<datasource-class>net.sourceforge.jtds.jdbcx.JtdsDataSource</datasource-class>
But when I test the connection I get an exception:
java.sql.SQLException: The serverName property has not been set.
at net.sourceforge.jtds.jdbcx.JtdsDataSource.getConnection(JtdsDataSource.java:150)
I was having the same issue after migrating to WFLY and resolved it by adding the properties.
This is what my complete *-ds.xml looks like:
<?xml version="1.0" encoding="UTF-8"?>
<datasources xmlns="http://www.jboss.org/ironjacamar/schema">
<datasource jndi-name="java:/xxxDS" pool-name="MSSQL">
<connection-url>
jdbc:sqlserver://localhost:1433;database=dbname;charset=UTF-8
</connection-url>
<driver>sqljdbc</driver>
<security>
<user-name>xxx</user-name>
<password>xxx</password>
</security>
<pool>
<!-- default is 0 -->
<min-pool-size>10</min-pool-size>
<!-- default is 20 -->
<max-pool-size>50</max-pool-size>
</pool>
<validation>
<valid-connection-checker
class-name="org.jboss.jca.adapters.jdbc.extensions.mssql.MSSQLValidConnectionChecker" />
<validate-on-match>false</validate-on-match>
<background-validation>true</background-validation>
<check-valid-connection-sql>select 1</check-valid-connection-sql>
<background-validation-millis>10000</background-validation-millis>
</validation>
</datasource>
For me, the valid-connection-checker was not adequate, but by adding the background validation with select 1 it was working.
We have moved over to using the jdbc driver directly from MSFT however:
<driver name="sqljdbc" module="mc.jdbc.sqljdbc">
<driver-class>com.microsoft.sqlserver.jdbc.SQLServerDriver</driver-class>
</driver>
That also might make a difference, however we had it set up with JBoss AS7 and the jdts driver for a long time.

Resources