SQL Server connection in Wildfly using JTDS driver - sql-server

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.

Related

JBoss/MSSQL Connection Pool Metrics

I have a system with JBoss EAP 6.3, and using MSSQL. I have the 'sqljdbc41.jar' set up and the datasource connection pool is configured in standalone.xml:
<datasource jndi-name="java:jboss/datasources/Foo" pool-name="Foo" enabled="true" use-ccm="false" connectable="true" statistics-enabled="true">
<connection-url>jdbc:sqlserver://<hostname>:1433;DatabaseName=<DB-Name></connection-url>
<driver-class>com.microsoft.sqlserver.jdbc.SQLServerDriver</driver-class>
<driver>sqlserver</driver>
<pool>
<min-pool-size>1</min-pool-size>
<max-pool-size>100</max-pool-size>
<prefill>true</prefill>
<use-strict-min>false</use-strict-min>
<flush-strategy>IdleConnections</flush-strategy>
<allow-multiple-users>true</allow-multiple-users>
</pool>
<security>
<user-name>user1</user-name>
<password>user1</password>
</security>
<timeout>
<blocking-timeout-millis>5000</blocking-timeout-millis>
<idle-timeout-minutes>4</idle-timeout-minutes>
</timeout>
<statement>
<share-prepared-statements>false</share-prepared-statements>
</statement>
</datasource>
The db queries are all running fine, but we are missing metrics around connection pool in our jboss console. Have tried to play around with the configuration but not sure if that's the right path. I haven't set up any specific jmx beans, maybe that's the issue?
Have you enabled the DataSource statistics? In EAP 6.3 and later, DataSource statistics must be explicitly enabled. They are disabled by default to minimize performance impact

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.

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>

What is causing this propel error?

I'm geting this error in propel when I run my app:
PropelException: Unable to open PDO connection [wrapped: SQLSTATE[HY000] [14] unable to open database file]
I've tried everything I can think of but can't figure out what is causing the problem.
my build.properties is:
propel.project = LinkCannon2
# The Propel driver to use for generating SQL, etc.
propel.database = sqlite
# This must be a PDO DSN
propel.database.url = sqlite://Users/GMan/Public/Source/LinkCannon2/test/data/LinkCannon2TestDB.sq3
propel.addGenericMutators = true
And my runtime-conf.xml is:
<propel>
<datasources default="LinkCannon2">
<datasource id="LinkCannon2"> <!-- this ID must match <database name=""> in schema.xml -->
<adapter>sqlite</adapter> <!-- sqlite, mysql, myssql, oracle, or pgsql -->
<connection>
<classname>DebugPDO</classname>
<dsn>sqlite://localhost///Users/GMan/Public/Source/LinkCannon2/test/data/LinkCannon2TestDB.sq3</dsn>
</connection>
</datasource>
</datasources>
<debugpdo>
<logging>
<details>
<method>
<enabled>true</enabled>
</method>
<time>
<enabled>true</enabled>
</time>
<mem>
<enabled>true</enabled>
</mem>
</details>
</logging>
</debugpdo>
</propel>
</config>
This is not probably not a problem specific to Propel, but to SQLite. If you search for the actual error message (SQLSTATE[HY000] [14] unable to open database file), you will find information about setting the right permissions and all that to make sure the process that executes the PHP script (for example, the Apache server) has access to this file.
Your dsn entry in runtime-conf.xml as well as your url in your build.properties don't seem correct.
Make sure that the patths are correct based on the platform you're using.

Resources