views:

1374

answers:

2

I can successfully run my Grails application in Jetty. It succeeds in connecting to my MsSql database and everything is fine. When I deploy that same application in Tomcat 6 on the same machine, I receive the following error on startup in the Tomcat log:

Caused by: java.net.ConnectException: Connection refused: connect

I don't believe that my MsSql server is the issue since I have another Java application running in the same instance of Tomcat and accessing the same database server successfully.

The connection string is exactly the same when I deploy it in Jetty and in Tomcat. Any ideas why I can't connect to my database when I deploy my Grails app in Tomcat 6? I can't seem to access any databases when my Grails app deployed in Tomcat. (My other Java app (Confluence) has no problem connecting.

Here is my connection info:

dataSource {
    pooled = true
    driverClassName = "net.sourceforge.jtds.jdbc.Driver"
    username = "user"
    password = "pass"
}
hibernate {
    cache.use_second_level_cache=true
    cache.use_query_cache=true
    cache.provider_class='com.opensymphony.oscache.hibernate.OSCacheProvider'
}
// environment specific settings
environments {
    development {
     dataSource {
      dbCreate = "update" // one of 'create', 'create-drop','update'
      url = "jdbc:jtds:sqlserver://localhost:1143/holidayCards"
     }
    }
    test { //for AD-DEV02
     dataSource {
      dbCreate = "update"
      url = "jdbc:jtds:sqlserver://AD-DEV02:1237/holidayCards;instance=SQL2005"
     }
    }
    production {
     dataSource {
      dbCreate = "update"
      url = "jdbc:jtds:sqlserver://SQL:1433/holidayCards"
     }
    }
}

I always deploy as 'test':

grails test war

As you'll see from my answer below, I don't think this is a connection issue since I was able to get to work successfully when I downgraded from grails 1.1beta1 to 1.0.4.

Any help is appreciated,

Andrew

+3  A: 

What does your DataSource.groovy file look like? When you run your app with 'grails run-app', Grails uses the datasource in the "development" section. When you produce a war file with 'grails war' and deploy it to an application server, Grails uses the datasource in the "production" section. You may need to make sure that your development and production datasource are configure the same.

Ben Williams
+1  A: 

This is an issue with grails 1.1beta1. When I reverted my application to grails 1.0.4, it seemed to work. Unfortunately, I had to change a couple pieces of code because the beta version of grails fixed some bugs, but this seems to be rooted in the version of grails I was using.

I just created an empty grails application using 1.1beta1 and I was able to successfully deploy it in Tomcat (and access the database). This makes me think that there are some other settings in my project that don't play well with the beta version. Perhaps it's my jquery plugin. Perhaps it was upgrading my project from grails 1.0.4 to 1.1beta1

This doesn't quite solve the issue, but it narrows it.

Andrew

anschoewe