tags:

views:

284

answers:

1

While trying to connect to a database that's set to read only, the connection cannot be made. I get the following error:

Cannot create PoolableConnectionFactory (Io exception: The Network Adapter could not 
establish the connection)

The application needs to run in read-write mode and then automatically handle the switch to read-only by only checking the isReadOnly property of the connection object. The application runs correctly when connecting to a read-write database, but fails when I change to the connection string below (with security information removed). I've verified that the connection string is correct, so the problem doesn't lie there.

ca.businesssolutions.nbs.jdbc.connect=jdbc:oracle:thin:unicorn_read_only/password@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=hostname)(PORT=9999)))(CONNECT_DATA=(SID=SBSBTST)(SERVER=DEDICATED)))

I'm having trouble trying to figure out where to start looking. I inherited the application and am not sure if it's a spring framework limitation or another setting I'm missing.

The spring configuration for the datasource is:

<bean id="dataSource" class="ca.businesssolutions.nbs.server.base.datasource.MyBasicDataSource"
      destroy-method="close">
    <!--url and driver class name are set through Configuratoin object.-->
    <property name="initialSize" value="10"/>
    <property name="maxActive" value="-1"/>
    <property name="validationQuery" value="SELECT 1 FROM DUAL"/>
    <property name="accessToUnderlyingConnectionAllowed" value="true"/>
</bean>

The Data Source constructor:

public MyBasicDataSource() {
    super();
    setUrl(Configuration.get(Configuration.CONNECT));
    setDriverClassName(Configuration.get(Configuration.DRIVER_NAME));
    //The initial number of connections that are created when the pool is started.
    int numConnections = 10;
    try {
        numConnections = Integer.parseInt(Configuration.get(Configuration.NUMBER_OF_CONNECTIONS));
    } catch (Exception exception) {
        // Do nothing.
    }
    setInitialSize(numConnections);
    //The maximum number of active connections that can be allocated from this pool at the same time, or non-positive for no limit.
    setMaxActive(-1);
    setValidationQuery("SELECT 1 FROM DUAL");
    setAccessToUnderlyingConnectionAllowed(true);
    DataAccessObject.setDataSource(this);
}

What else would help?

+1  A: 

What's the difference between read/write and read-only connect string? Is there any chance for a typo? Have you tried this connect string from another tool (but from the same host)? Try using a Java GUI Tool on the same computer that you have difficulties connecting from. Use Copy/Paste with your exact connection string.

If this doesn't work either, you might have an unresolvable hostname, firewall issues or something else. If it does work from the same computer leave a comment.

Olaf
Thanks. I found the typo. It was an unresolvable hostname.
jgreep