Tomcat connection pooling reset by sql server 2008 and 2012 - sql-server

I have 5 different modules connecting sql server 2008 and 2012 using Tomcat connection pooling.
In the Tomcat7\conf\context.xml
<Resource auth="Container" driverClassName="net.sourceforge.jtds.jdbc.Driver" logAbandoned="true" maxActive="100" maxIdle="30" maxWait="10000" name="jdbc/testservice2" password="abc" removeAbandoned="true" removeAbandonedTimeout="60" type="javax.sql.DataSource"
url="jdbc:jtds:sqlserver://localhost;databaseName=testdb;SelectMethod=Cursor" username="abc"/>
Module 1 - In the Tomcat7\conf\localhost\Module1.XML
<?xml version="1.0" encoding="UTF-8"?>
<Context antiJARLocking="true" path="/Module1">
<Resource name="jdbc/testdb" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000" removeAbandoned="true" removeAbandonedTimeout="60"
username="abc" password="abc" driverClassName="net.sourceforge.jtds.jdbc.Driver"
url="jdbc:jtds:sqlserver://localhost;databaseName=testdb;SelectMethod=Cursor"/>
Module 2 - In the Tomcat7\conf\localhost\Module2.XML
<?xml version="1.0" encoding="UTF-8"?>
<Context antiJARLocking="true" path="/Module2">
<Resource name="jdbc/testdb" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000" removeAbandoned="true" removeAbandonedTimeout="60"
username="abc" password="abc" driverClassName="net.sourceforge.jtds.jdbc.Driver"
url="jdbc:jtds:sqlserver://localhost;databaseName=testdb;SelectMethod=Cursor"/>
</Context>
Module 3 - In the Tomcat7\conf\localhost\Module3.XML
<Context antiJARLocking="true" path="/Module3">
<Resource name="jdbc/testdb" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000" removeAbandoned="true" removeAbandonedTimeout="60"
username="abc" password="abc" driverClassName="net.sourceforge.jtds.jdbc.Driver"
url="jdbc:jtds:sqlserver://localhost;databaseName=testdb;SelectMethod=Cursor"/>
</Context>
Module 4 - In the Tomcat7\conf\localhost\Module4.XML
<Context antiJARLocking="true" path="/Module4">
<Resource name="jdbc/testdb" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000" removeAbandoned="true" removeAbandonedTimeout="60"
username="abc" password="abc" driverClassName="net.sourceforge.jtds.jdbc.Driver"
url="jdbc:jtds:sqlserver://localhost;databaseName=testdb;SelectMethod=Cursor"/>
</Context>
I'm experiencing the below error on QA server as well as staging server?
06-Apr-2015 07:43:28 ERROR DBAccess:49 - I/O Error: Connection reset by peer: socket write error
What's wrong with my Tomcat 7 connection pool configuration? why it's rejected by sql server

You are trying to use all the modules simultaneously in which you have defined the 'Resource' with same name i.e. name="jdbc/testdb" as far as i know this name has to be unique because it is jndi bound with the value you give to name attribute(see tomcat document https://tomcat.apache.org/tomcat-7.0-doc/config/context.html#Resource_Definitions ). If you define a datasource with same name in different modules(web apps) see that they are not in use simultaneously. Somewhere in your server this is happening. To be safe use different name for 'Resource'.
Another thing-Is 'Resource' with name="jdbc/testservice2" being used in any of your five modules you have mentioned. Cause I don't see a connection between any of your five modules with this 'Resource'.

Related

Issues while setting up vespa on multiple docker containers

I have two dockers sitting on two different machines, both running the vespa. When I submit an application which have two nodes - vespa1 and vespa2 (resolved in /etc/hosts). I get the following error.
Uploading application '/vespa-eval/src/main/application/' using http://localhost:19071/application/v2/tenant/default/session?name=application
Session 6 for tenant 'default' created.
Preparing session 6 using
http://localhost:19071/application/v2/tenant/default/session/6/prepared
Request failed. HTTP status code: 400
Invalid application package: default.default: Error loading model:
Could not find host in the application's host system: 'vespa-container'. Hostsystem=host 'vespa1',host 'vespa2'
I do not have a problem when using only localhost.
hosts.xml
<?xml version="1.0" encoding="utf-8" ?>
<hosts>
<host name="vespa1">
<alias>node0</alias>
</host>
<host name="vespa2">
<alias>node1</alias>
</host>
</hosts>
services.xml
<?xml version="1.0" encoding="utf-8" ?>
<services version="1.0">
<admin version="2.0">
<adminserver hostalias="node0"/>
<configservers>
<configserver hostalias="node0"/>
</configservers>
</admin>
<container id="container" version="1.0">
<document-api />
<search />
<nodes>
<node hostalias="node0" />
<node hostalias="node1" />
</nodes>
</container>
<content id="product" version="1.0">
<redundancy>1</redundancy>
<documents>
<document type="product" mode="index" />
</documents>
<nodes>
<node hostalias="node0" distribution-key="0" />
<node hostalias="node1" distribution-key="1" />
</nodes>
</content>
</services>
Looks like a host named vespa-container is already deployed but not in the new application package. To debug, try
vespa-model-inspect hosts
on the config server and see if it lists the host. Maybe a good idea to try from scratch, I don't see anything wrong with the enclosed files. To clean the config server, search for
vespa-configserver-remove-state
in the documentation
I came across the same issue, and fixed the error by replacing 'vespa-container' (below command) to the hostname of physical box. However, this caused a couple of other errors in rpc connection. Did you fix the problem yet? #aman.gupta
docker run --detach --name vespa --hostname vespa-container --privileged \
--volume $VESPA_SAMPLE_APPS:/vespa-sample-apps --publish 8080:8080 vespaengine/vespa

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>

Unable to install/run SQL Server driver in WildFly 10

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>

tomcat JNDI database configuration

I have the following in C:/Tomcat6/conf/context.xml:
<Context>
<!-- Default set of monitored resources -->
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<ResourceLink global="jdbc/MyDatasource" name="jdbc/MyDatasource" type="javax.sql.DataSource"/>
</Context>
and the following in C:/Tomcat6/conf/server.xml:
<Resource name="jdbc/MyDatasource"
auth="Container"
driverClassName="net.sourceforge.jtds.jdbc.Driver"
maxactive="100"
maxidle="30"
maxwait="10000"
type="javax.sql.DataSource"
jdbcUrl="jdbc:jtds:sqlserver://localhost/SAFEHOUSE-UK;integratedSecurity=true;">
I have jtds-1.2.5.jar in C:/Tomcat6/lib.
Yet when I hit my application I get the following:
org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC
driver of class 'net.sourceforge.jtds.jdbc.Driver' for connect URL
'null' at
org.apache.tomcat.dbcp.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1452)
at
org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1371)
at
org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
at
com.safehouse.safeservices.authenticate.AdminLoginForm.getpassword(Unknown
Source)
Any help would be much appreciated
1、modify the connection url
jdbcUrl="jdbc:jtds:sqlserver://localhost:1305;DatabaseName=your databasename"
From Apache Tomcat 6 documentation: https://tomcat.apache.org/tomcat-6.0-doc/jndi-datasource-examples-howto.html
maybe the mistake was in attribute name, try to use url instead of jdbcUrl

Trying to access JNDI source on Tomcat server

I have a application running on Jboss server. on Jboss it uses JNDI sources for DB connection name cc.xml & iv.xml.(jboss/server/default/deploy/ Both jndi xml are here)
Now i have to deploy the same war on Tomcat and trying to create & access the JNDI sources from tomcat. I made following changes -
Added following code to META-INF/Context.xml
<?xml version="1.0" encoding="UTF-8"?>
<Context path="/R2">
<ResourceLink name="ivrDataSource" global="ivrDataSource" type="javax.sql.DataSource" />
<Resource
name="ivrDataSource"
type="javax.sql.DataSource"
driverClassName="net.sourceforge.jtds.jdbc.Driver"
password=""
maxIdle="2"
maxWait="5000"
username="user"
url="jdbc:jtds:sqlserver://abc:1433;DatabaseName=IVR_GUARDIAN;tds=8.0;lastupdatecount=false;socketKeepAlive=true;"
maxActive="4"/>
<ResourceLink name="ccDataSource" global="ccDataSource" type="javax.sql.DataSource" />
<Resource
name="ccDataSource"
type="javax.sql.DataSource"
driverClassName="net.sourceforge.jtds.jdbc.Driver"
password=""
maxIdle="2"
maxWait="5000"
username="web"
url="jdbc:jtds:sqlserver://xyz:1433;DatabaseName=CC_GUARDIAN;tds=8.0;lastupdatecount=false;socketKeepAlive=true;"
maxActive="4"/>
</Context>
ADDED BELOW TO WEB.XML ----
<!-- FOR TOMCAT DEPLOYMRNT -TESTING -->
<resource-ref>
<description>ccDataSource</description>
<res-ref-name>ccDataSource</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
<resource-ref>
<description>ivrDataSource</description>
<res-ref-name>ivrDataSource</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
But i am getting error-
javax.naming.NameNotFoundException: Name ccDataSource,ivrDataSource is not bound in this Context.
Always worked on JBOSS so this is new to me..Missing something here.Please suggest.
You do not have to use <ResourceLink>. Try removing <ResourceLink>s.
<ResourceLink> is used to create a link to a global JNDI resource.
Please see following links for more details.
http://tomcat.apache.org/tomcat-7.0-doc/jndi-resources-howto.html
http://tomcat.apache.org/tomcat-7.0-doc/config/context.html#Resource%20Links
Hope this helps.

Resources