Unable to install/run SQL Server driver in WildFly 10 - sql-server

I am running my application on a WildFly 10 server. I do not wish to place my connection details on my application src codes thus am trying to place it inside WildFly 10 server itself.
However I am facing issues.
Under [WILDFLY_HOME]\modules\system\layers\base\com\microsoft,
I created the following directory sqlserver\main and I place my JAR file and my XML file inside the main folder.
The JAR that I am using is sqljdbc.jar.
module.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!-- JDBC Drivers module.xml file to configure your JDBC drivers-->
<!-- SQL Server 2014 example -->
<module xmlns="urn:jboss:module:1.3" name="com.microsoft.sqlserver">
<resources>
<resource-root path="sqljdbc.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
</dependencies>
</module>
Next under [WILDFLY_HOME]\standalone\configuration, I modified the standalone.xml. Under the subsystem datasource section, I add the details for SQL Server.
standalone.xml:
<subsystem xmlns="urn:jboss:domain:datasources:4.0">
<datasources>
<datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="ExampleDS" enabled="true" use-java-context="true">
<connection-url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE</connection-url>
<driver>h2</driver>
<security>
<user-name>sa</user-name>
<password>sa</password>
</security>
</datasource>
<datasource jndi-name="java:/TestDS" pool-name="TestDS" enabled="true" use-java-context="true">
<connection-url>jdbc:sqlserver://localhost\test:1433;databaseName=test</connection-url>
<driver>mssql</driver>
<security>
<user-name>sa</user-name>
<password>Password123!</password>
</security>
<pool>
<min-pool-size>5</min-pool-size>
<max-pool-size>50</max-pool-size>
<prefill>false</prefill>
<use-strict-min>false</use-strict-min>
<flush-strategy>FailingConnectionOnly</flush-strategy>
</pool>
<validation>
<valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.mssql.MSSQLValidConnectionChecker"></valid-connection-checker>
</validation>
</datasource>
<drivers>
<driver name="h2" module="com.h2database.h2">
<xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
</driver>
<driver name="mssql" module="com.microsoft.sqlserver">
<xa-datasource-class>com.microsoft.sqlserver.jdbc.SQLServerDriver</xa-datasource-class>
</driver>
</drivers>
</datasources>
</subsystem>
The error that I am facing now is as per below when I start running my WildFly:
15:19:51,098 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("add") failed - address: ([
("subsystem" => "datasources"),
("data-source" => "TestDS")
]) - failure description: {
"WFLYCTL0412: Required services that are not installed:" => [
"jboss.jdbc-driver.mssql",
"jboss.jdbc-driver.mssql"
],
"WFLYCTL0180: Services with missing/unavailable dependencies" => [
"org.wildfly.data-source.TestDS is missing [jboss.jdbc-driver.mssql]",
"jboss.driver-demander.java:/TestDS is missing [jboss.jdbc-driver.mssql]",
"org.wildfly.data-source.TestDS is missing [jboss.jdbc-driver.mssql]"
]
}
15:19:51,120 INFO [org.jboss.as.controller] (Controller Boot Thread) WFLYCTL0183: Service status report
WFLYCTL0184: New missing/unsatisfied dependencies:
service jboss.jdbc-driver.mssql (missing) dependents: [service org.wildfly.data-source.TestDS, service jboss.driver-demander.java:/TestDS]

I managed to resolve the issue with this.
Since I place the file under this directory: [WILDFLY_HOME]\modules\system\layers\base\com\microsoft
Then the correct module location should be as per follow for normal datasource:
<driver name="mssql" module="system.layers.base.com.microsoft.sqlserver">
<driver-class>com.microsoft.sqlserver.jdbc.SQLServerDriver</driver-class>
</driver>
or
if you are using xa datasource:
<driver name="mssql" module="com.microsoft.sqlserver">
<xa-datasource-class>com.microsoft.sqlserver.jdbc.SQLServerXADataSource</xa-datasource-class>
</driver>
credits to #jklee

The driver is wrong, use
<driver name="mssql" module="com.microsoft.sqlserver">
<xa-datasource-class>com.microsoft.sqlserver.jdbc.SQLServerXADataSource</xa-datasource-class>
</driver>
or
<driver name="mssql" module="com.microsoft.sqlserver">
<driver-class>com.microsoft.sqlserver.jdbc.SQLServerDriver</driver-class>
</driver>

You can add sqlserver as global module as shown below
<subsystem xmlns="urn:jboss:domain:ee:4.0">
<global-modules>
<module name="com.microsoft.sqlserver" slot="main"/>
<module name="com.sql.mysql" slot="main"/>
</global-modules>
.
.
</subsystem>

Related

Wildfly 14 Microsoft SQL Server Configuration

I want to use MS SQL Server as a datasource in Wildfly 14, but I always get following error in the console:
ERROR [org.jboss.as.controller.management-operation] (ServerService Thread Pool -- 41) WFLYCTL0013: Operation ("add") failed - address: ([("subsystem" => "datasources"),("jdbc-driver" => "sqlserver")]) - failure description: "WFLYJCA0115: Module for driver [com.microsoft.sqlserver.jdbc] or one of it dependencies is missing: [com.microsoft.sqlserver.jdbc]"
My configuration is as follow:
standalone.xml
<drivers>
<driver name="sqlserver" module="com.microsoft.sqlserver">
<xa-datasource-class>com.microsoft.sqlserver.jdbc.SQLServerDriver</xa-datasource-class>
</driver>
</drivers>
I also configured a module.xml in the following directory: wildfly-14.0.1.Final\modules\system\layers\base\com\microsoft\sqlserver\main. I also put the sqljdbc42.jar in it.
<module xmlns="urn:jboss:module:1.3" name="com.microsoft.sqlserver.jdbc">
<resources>
<resource-root path="sqljdbc42.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
</dependencies>
</module>
With Wildfly 13 and before I had no problems.
I believe your driver configuration in the standalone.xml is still wrong.
The following have to be the same.
In standalone.xml:
<driver name="sqlserver" module="com.microsoft.sqlserver.jdbc">
In module.xml:
<module xmlns="urn:jboss:module:1.3" name="com.microsoft.sqlserver.jdbc">
Location of sqljdbc42.jar and module.xml:
JBOSS_HOME\modules\com\microsoft\sqlserver\jdbc\main\
I also believe you are using the wrong xa-datasource-class, this should be:
com.microsoft.sqlserver.jdbc.SQLServerXADataSource
Also have a look at EAP7 Documentation. It should be the same vor wildfly.
There is also a good example of how to use the CLI.
add this to module.xml inside <dependencies> tag
<module name="javax.xml.bind.api"/>

Camunda: Configure/setup MS SQL server database for rest api

By default, camunda rest api uses H2 database.
I'm unable to locate the file where I can configure the rest api to use Microsoft SQL Server.
Apologies for not being much clear as I am new to camunda.
You can find information's about configure the JDBC connections in the Camunda installation Guide.
For Example for Tomcat (you have to simply edit the driverClassName, url and the credentials).
To configure a JDBC Resource you have to edit the file
$TOMCAT_HOME/conf/server.xml. This could look like the following
example for an H2 database:
<Server>
...
<GlobalNamingResources>
...
<Resource name="jdbc/ProcessEngine"
auth="Container"
type="javax.sql.DataSource"
factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
uniqueResourceName="process-engine"
driverClassName="org.h2.Driver"
url="jdbc:h2:./camunda-h2-dbs/process-engine;MVCC=TRUE;TRACE_LEVEL_FILE=0"
username="sa"
password=""
maxActive="20"
minIdle="5" />
</GlobalNamingResources>
</Server>
For JBoss or Wildfly you have to edit the standalone/configuration/standalone.xml:
Add a datasource and driver tag, which could like the following, to the datasources.
<datasource jta="true" enabled="true" use-java-context="true" use-ccm="true"
jndi-name="java:jboss/datasources/ProcessEngine"
pool-name="ProcessEngine">
<connection-url>jdbc:sqlserver://SERVER_NAME:SERVER_PORT;databaseName=DB_NAME</connection-url>
<driver>sqlserver2008</driver>
<security>
<user-name>USERNAME</user-name>
<password>PASSWORD</password>
</security>
<pool>
<min-pool-size>5</min-pool-size>
<max-pool-size>50</max-pool-size>
<prefill>false</prefill>
<use-strict-min>false</use-strict-min>
<flush-strategy>FailingConnectionOnly</flush-strategy>
</pool>
<validation>
<valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.mssql.MSSQLValidConnectionChecker"></valid-connection-checker>
</validation>
</datasource>
<drivers>
<driver name="sqlserver2008" module="com.microsoft">
<driver-class>com.microsoft.sqlserver.jdbc.SQLServerDriver</driver-class>
</driver>
</drivers>

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.

How to connect JBoss 7.1.1 Final to Oracle Database?

I looked over the Internet but I couldn't find any easy tutorials or docs explaining the problem.
I want to connect my JBoss 7.1.1 Final to Oracle Database. I am using Oracle Database 11g Express Edition on 64bit Windows.
The question is what should I do to connect my jboss to Oracle DB?
Check this answer jboss 7 oracle datasource configuration
In short, you have to declare a jboss module for your oracle driver.
Then, you create your datasource in standalone-xxx.xml and add the reference to the driver.
Finally, you can use this datasource in any persistence.xml by using the jndi-name declared in the datasource.
All of this is explained in the url provided.
Good luck!
You can create JNDI in Jboss 7.1.1 as below and configure mybatis to use this JNDI. make sure you have oracle driver in Modules at com.oracle.ojdbc localtion.
<subsystem xmlns="urn:jboss:domain:datasources:1.0">
<datasources>
<datasource jta="true" jndi-name="java:/jdbc/test" pool-name="test" enabled="true" use-java-context="true" use-ccm="true">
<connection-url>jdbc:oracle:thin:#localhost:1521:testDB</connection-url>
<driver>oracle</driver>
<pool>
<min-pool-size>2</min-pool-size>
<max-pool-size>100</max-pool-size>
<prefill>false</prefill>
</pool>
<security>
<user-name>username</user-name>
<password>password</password>
</security>
<validation>
<validate-on-match>false</validate-on-match>
<background-validation>false</background-validation>
</validation>
</datasource>
<drivers>
<driver name="oracle" module="com.oracle.ojdbc">
<driver-class>oracle.jdbc.OracleDriver</driver-class>
<xa-datasource-class>oracle.jdbc.xa.client.OracleXADataSource</xa-datasource-class>
</driver>
</drivers>
</datasources>
</subsystem>

Resources