Friday, September 17, 2010

SqlServer 2008 Connection Refused to Grails

I was setting up a test application on my development machine and I had everything configured, but the application would not start.  After reviewing the error message, somewhere near the bottom, it said "Connection Refused".

The machine was running Windows 7, Sql Server 2008, and Grails 1.3.4. I was using the jTDS JDBC Driver 1.2.5 to connect to the database (just drop the jar in the lib directory).  After searching for about 30 minutes, I found that TCP/IP access in SQL Server 2005/2008 is disabled by default.

To enable it, you can do this:



SQL Server Configuration Manager
-->SQL Server 2005 Network Configuration
-->TCP/IP
-->IP  Address
-->TCP port


You'll need to enable it, set the port, set the IP, then restart the SQLServer service.


Here is what my DataSource.groovy looks like:


dataSource {
    pooled = true
    driverClassName ="net.sourceforge.jtds.jdbc.Driver"
    dialect = "org.hibernate.dialect.SQLServerDialect"
}

hibernate {
    cache.use_second_level_cache=true
    cache.use_query_cache=true
    cache.provider_class="com.opensymphony.oscache.hibernate.OSCacheProvider"
    connection.pool_size=10
}

// environment specific settings
environments {
    development {
        dataSource {
            url = "jdbc:jtds:sqlserver://laptop_win7:1433;databaseName=gpay_DEV"
            username = "GPayAdmin"
            password = "MyPassword123!"
            
        }
    }
}