jboss 7 AS datasource for sqlserver

With Jboss 7.1.1 I managed to get it working without specifying module.

Just put sqljdbc4.jar into deployment directory: %JBOSSHOME%\standalone\deployments

Configuration needed for datasource in standalone.xml is as follows:

<datasource jndi-name="java:jboss/datasources/myPool" pool-name="myPool" enabled="true" use-java-context="true">
    <connection-url>jdbc:sqlserver://127.0.0.1:1433;databaseName=myName;</connection-url>
    <driver>sqljdbc4.jar</driver>
    <pool>
        <min-pool-size>10</min-pool-size>
        <max-pool-size>100</max-pool-size>
        <prefill>true</prefill>
    </pool>
    <security>
        <user-name>myUser</user-name>
        <password>myPassword</password>
    </security>
    <statement>
        <prepared-statement-cache-size>32</prepared-statement-cache-size>
        <share-prepared-statements>true</share-prepared-statements>
    </statement>
</datasource>

got the same error like you before

instead of %jbosshome%\modules\com\microsoft\sqlserver\jdbc\

try %jbosshome%\modules\com\microsoft\sqlserver\jdbc\main

and put the .jar of the jdbc driver and the module.xml overthere.


using Jboss AS 7.1.1, as well as putting the module in %jbosshome%\modules\com\microsoft\sqlserver\jdbc\main I had to make a slight change to the xml - the driver element in standalone.xml should be :

 <driver name="sqljdbc" module="com.microsoft.sqlserver.jdbc">
      <driver-class>
           com.microsoft.sqlserver.jdbc.SQLServerDriver
      </driver-class>
 </driver>

and the module.xml should be:

<?xml version="1.0" encoding="UTF-8"?>

<module xmlns="urn:jboss:module:1.1" name="com.microsoft.sqlserver.jdbc">

    <resources>
        <resource-root path="sqljdbc4.jar"/>
    </resources>
    <dependencies>
        <module name="javax.api"/>
        <module name="javax.transaction.api"/>
        <module name="javax.servlet.api" optional="true"/>
    </dependencies>

</module>

I used this configuration and it worked OK on AS7

<datasource jndi-name="java:jboss/datasources/stagingDS" pool-name="stagingDS" enabled="true" use-java-context="true">
    <connection-url>jdbc:sqlserver://linp-sqlrpt-01;databaseName=pmdm</connection-url>
    <driver-class>com.microsoft.sqlserver.jdbc.SQLServerDriver</driver-class>
    <driver>sqlserver</driver>
    <security>
        <user-name>username</user-name>
        <password>password</password>
    </security>
 </datasource>

<drivers>
    <driver name="sqlserver" module="com.microsoft.jdbc">
        <xa-datasource-class>com.microsoft.sqlserver.jdbc.SQLServerXADataSource</xa-datasource-class>
    </driver>
</drivers>

Of course if you're not using the distributed DataSource you can configure the regular driver class as previously defined.

The module file looks like this.

<module xmlns="urn:jboss:module:1.1" name="com.microsoft.jdbc">
    <properties>
        <property name="jboss.api" value="private"/>
    </properties>

    <resources>
        <resource-root path="sqljdbc4.jar"/>
    </resources>

    <dependencies>
       <module name="javax.api"/>
       <module name="javax.transaction.api"/>
       <module name="javax.servlet.api" optional="true"/>
    </dependencies>
</module>