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
-->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 {

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