4

I tried to create my first grails app, but there is some problems with connection my app to MSSQL server.

My actions were(by windows cmd):

  1. Command grails create-app hello
  2. Command cd hello
  3. After that I configured dataSource file:

    dataSource {
    
    pooled = true
    jmxExport = true
    driverClassName = "com.microsoft.sqlserver.jdbc.SQLServerDriver"
    username = "login"
    password = "password" }
    
    environments {
    
    development {
        dataSource {
            dbCreate = "update"
            url = "jdbc:jtds:sqlserver:\\<server-ip>;databaseName=Grails"
        }
    }
    test {
        dataSource {
            dbCreate = "update"
            url = "jdbc:jtds:sqlserver:\\<server-ip>;databaseName=Grails"
        }
    }
    production {
        dataSource {
            dbCreate = "update"
            url = "jdbc:jtds:sqlserver:\\<server-ip>;databaseName=Grails"
    
        }
    } 
    }
    

    Base "Grails" was alredy created in SQL Server.

  4. Command grails create-domain-class Hi

    Then I configured domain class Hi.groovy

    class Hi { 
       String word  
       int num
       static constraints = {
       } 
    }
    
  5. And finally I ran my app by command grails run-app

I think that in my Grails base should create new table Hi with two fields, but i get error with such stacktrace:

    | Configuring classpath
ёхэ 01, 2014 2:54:33 PM java.util.prefs.WindowsPreferences <init>
WARNING: Could not open/create prefs root node Software\JavaSoft\Prefs at root 0
| Running Grails application
Error |
2014-09-01 14:54:50,750 [localhost-startStop-1] ERROR pool.ConnectionPool  - Una
ble to create initial connections of pool.
Message: com.microsoft.sqlserver.jdbc.SQLServerDriver
    Line | Method
->>  334 | innerRun  in java.util.concurrent.FutureTask$Sync
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|    166 | run       in java.util.concurrent.FutureTask
|   1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    615 | run       in java.util.concurrent.ThreadPoolExecutor$Worker
^    722 | run . . . in java.lang.Thread
Caused by ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver
->>  366 | run       in java.net.URLClassLoader$1
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|    355 | run       in     ''
|    354 | findClass in java.net.URLClassLoader
|    423 | loadClass in java.lang.ClassLoader
|    266 | forName . in java.lang.Class
|    334 | innerRun  in java.util.concurrent.FutureTask$Sync
|    166 | run . . . in java.util.concurrent.FutureTask
|   1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^    722 | run       in java.lang.Thread
Error |
2014-09-01 14:54:50,798 [localhost-startStop-1] ERROR pool.ConnectionPool  - Una
ble to create initial connections of pool.
Message: com.microsoft.sqlserver.jdbc.SQLServerDriver
    Line | Method
->>  334 | innerRun  in java.util.concurrent.FutureTask$Sync
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|    166 | run       in java.util.concurrent.FutureTask
|   1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    615 | run       in java.util.concurrent.ThreadPoolExecutor$Worker
^    722 | run . . . in java.lang.Thread
Caused by ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver
->>  366 | run       in java.net.URLClassLoader$1
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|    355 | run       in     ''
|    354 | findClass in java.net.URLClassLoader
|    423 | loadClass in java.lang.ClassLoader
|    266 | forName . in java.lang.Class
|    334 | innerRun  in java.util.concurrent.FutureTask$Sync
|    166 | run . . . in java.util.concurrent.FutureTask
|   1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^    722 | run       in java.lang.Thread
Error |
2014-09-01 14:54:50,841 [localhost-startStop-1] ERROR pool.ConnectionPool  - Una
ble to create initial connections of pool.
Message: com.microsoft.sqlserver.jdbc.SQLServerDriver
    Line | Method
->>  334 | innerRun  in java.util.concurrent.FutureTask$Sync
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|    166 | run       in java.util.concurrent.FutureTask
|   1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    615 | run       in java.util.concurrent.ThreadPoolExecutor$Worker
^    722 | run . . . in java.lang.Thread
Caused by ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver
->>  366 | run       in java.net.URLClassLoader$1
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|    355 | run       in     ''
|    354 | findClass in java.net.URLClassLoader
|    423 | loadClass in java.lang.ClassLoader
|    266 | forName . in java.lang.Class
|    334 | innerRun  in java.util.concurrent.FutureTask$Sync
|    166 | run . . . in java.util.concurrent.FutureTask
|   1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^    722 | run       in java.lang.Thread
Error |
2014-09-01 14:54:50,860 [localhost-startStop-1] ERROR context.GrailsContextLoade
rListener  - Error initializing the application: Error creating bean with name '
transactionManagerPostProcessor': Initialization of bean failed; nested exceptio
n is org.springframework.beans.factory.BeanCreationException: Error creating bea
n with name 'transactionManager': Cannot resolve reference to bean 'sessionFacto
ry' while setting bean property 'sessionFactory'; nested exception is org.spring
framework.beans.factory.BeanCreationException: Error creating bean with name 'se
ssionFactory': Cannot resolve reference to bean 'hibernateProperties' while sett
ing bean property 'hibernateProperties'; nested exception is org.springframework
.beans.factory.BeanCreationException: Error creating bean with name 'hibernatePr
operties': Cannot resolve reference to bean 'dialectDetector' while setting bean
 property 'properties' with key [hibernate.dialect]; nested exception is org.spr
ingframework.beans.factory.BeanCreationException: Error creating bean with name
'dialectDetector': Invocation of init method failed; nested exception is org.spr
ingframework.jdbc.support.MetaDataAccessException: Error while extracting Databa
seMetaData; nested exception is java.sql.SQLException: com.microsoft.sqlserver.j
dbc.SQLServerDriver
Message: Error creating bean with name 'transactionManagerPostProcessor': Initia
lization of bean failed; nested exception is org.springframework.beans.factory.B
eanCreationException: Error creating bean with name 'transactionManager': Cannot
 resolve reference to bean 'sessionFactory' while setting bean property 'session
Factory'; nested exception is org.springframework.beans.factory.BeanCreationExce
ption: Error creating bean with name 'sessionFactory': Cannot resolve reference
to bean 'hibernateProperties' while setting bean property 'hibernateProperties';
 nested exception is org.springframework.beans.factory.BeanCreationException: Er
ror creating bean with name 'hibernateProperties': Cannot resolve reference to b
ean 'dialectDetector' while setting bean property 'properties' with key [hiberna
te.dialect]; nested exception is org.springframework.beans.factory.BeanCreationE
xception: Error creating bean with name 'dialectDetector': Invocation of init me
thod failed; nested exception is org.springframework.jdbc.support.MetaDataAccess
Exception: Error while extracting DatabaseMetaData; nested exception is java.sql
.SQLException: com.microsoft.sqlserver.jdbc.SQLServerDriver
    Line | Method
->>  334 | innerRun  in java.util.concurrent.FutureTask$Sync
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|    166 | run       in java.util.concurrent.FutureTask
|   1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    615 | run       in java.util.concurrent.ThreadPoolExecutor$Worker
^    722 | run . . . in java.lang.Thread
Caused by BeanCreationException: Error creating bean with name 'transactionManag
er': Cannot resolve reference to bean 'sessionFactory' while setting bean proper
ty 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanC
reationException: Error creating bean with name 'sessionFactory': Cannot resolve
 reference to bean 'hibernateProperties' while setting bean property 'hibernateP
roperties'; nested exception is org.springframework.beans.factory.BeanCreationEx
ception: Error creating bean with name 'hibernateProperties': Cannot resolve ref
erence to bean 'dialectDetector' while setting bean property 'properties' with k
ey [hibernate.dialect]; nested exception is org.springframework.beans.factory.Be
anCreationException: Error creating bean with name 'dialectDetector': Invocation
 of init method failed; nested exception is org.springframework.jdbc.support.Met
aDataAccessException: Error while extracting DatabaseMetaData; nested exception
is java.sql.SQLException: com.microsoft.sqlserver.jdbc.SQLServerDriver
->>  334 | innerRun  in java.util.concurrent.FutureTask$Sync
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|    166 | run       in java.util.concurrent.FutureTask
|   1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    615 | run       in java.util.concurrent.ThreadPoolExecutor$Worker
^    722 | run . . . in java.lang.Thread
Caused by BeanCreationException: Error creating bean with name 'sessionFactory':
 Cannot resolve reference to bean 'hibernateProperties' while setting bean prope
rty 'hibernateProperties'; nested exception is org.springframework.beans.factory
.BeanCreationException: Error creating bean with name 'hibernateProperties': Can
not resolve reference to bean 'dialectDetector' while setting bean property 'pro
perties' with key [hibernate.dialect]; nested exception is org.springframework.b
eans.factory.BeanCreationException: Error creating bean with name 'dialectDetect
or': Invocation of init method failed; nested exception is org.springframework.j
dbc.support.MetaDataAccessException: Error while extracting DatabaseMetaData; ne
sted exception is java.sql.SQLException: com.microsoft.sqlserver.jdbc.SQLServerD
river
->>  334 | innerRun  in java.util.concurrent.FutureTask$Sync
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|    166 | run       in java.util.concurrent.FutureTask
|   1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    615 | run       in java.util.concurrent.ThreadPoolExecutor$Worker
^    722 | run . . . in java.lang.Thread
Caused by BeanCreationException: Error creating bean with name 'hibernatePropert
ies': Cannot resolve reference to bean 'dialectDetector' while setting bean prop
erty 'properties' with key [hibernate.dialect]; nested exception is org.springfr
amework.beans.factory.BeanCreationException: Error creating bean with name 'dial
ectDetector': Invocation of init method failed; nested exception is org.springfr
amework.jdbc.support.MetaDataAccessException: Error while extracting DatabaseMet
aData; nested exception is java.sql.SQLException: com.microsoft.sqlserver.jdbc.S
QLServerDriver
->>  334 | innerRun  in java.util.concurrent.FutureTask$Sync
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|    166 | run       in java.util.concurrent.FutureTask
|   1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    615 | run       in java.util.concurrent.ThreadPoolExecutor$Worker
^    722 | run . . . in java.lang.Thread
Caused by BeanCreationException: Error creating bean with name 'dialectDetector'
: Invocation of init method failed; nested exception is org.springframework.jdbc
.support.MetaDataAccessException: Error while extracting DatabaseMetaData; neste
d exception is java.sql.SQLException: com.microsoft.sqlserver.jdbc.SQLServerDriv
er
->>  334 | innerRun  in java.util.concurrent.FutureTask$Sync
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|    166 | run       in java.util.concurrent.FutureTask
|   1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    615 | run       in java.util.concurrent.ThreadPoolExecutor$Worker
^    722 | run . . . in java.lang.Thread
Caused by MetaDataAccessException: Error while extracting DatabaseMetaData; nest
ed exception is java.sql.SQLException: com.microsoft.sqlserver.jdbc.SQLServerDri
ver
->>  334 | innerRun  in java.util.concurrent.FutureTask$Sync
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|    166 | run       in java.util.concurrent.FutureTask
|   1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    615 | run       in java.util.concurrent.ThreadPoolExecutor$Worker
^    722 | run . . . in java.lang.Thread
Caused by SQLException: com.microsoft.sqlserver.jdbc.SQLServerDriver
->>  334 | innerRun  in java.util.concurrent.FutureTask$Sync
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|    166 | run       in java.util.concurrent.FutureTask
|   1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    615 | run       in java.util.concurrent.ThreadPoolExecutor$Worker
^    722 | run . . . in java.lang.Thread
Caused by ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver
->>  366 | run       in java.net.URLClassLoader$1
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|    355 | run       in     ''
|    354 | findClass in java.net.URLClassLoader
|    423 | loadClass in java.lang.ClassLoader
|    266 | forName . in java.lang.Class
|    334 | innerRun  in java.util.concurrent.FutureTask$Sync
|    166 | run . . . in java.util.concurrent.FutureTask
|   1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^    722 | run       in java.lang.Thread
| Error Forked Grails VM exited with error

What am I doing wrong?

potashin
  • 44,205
  • 11
  • 83
  • 107
AlexandrM
  • 137
  • 2
  • 11

1 Answers1

6

The cause is that the JDBC driver cannot be loaded, as reported in the traces:

ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver

I use the following in my DataSource.groovy:

driverClassName = "net.sourceforge.jtds.jdbc.Driver"
dialect = "org.hibernate.dialect.SQLServerDialect"

And in BuildConfig.groovy put something like:

dependencies {
    runtime 'net.sourceforge.jtds:jtds:1.3.0'
}
potashin
  • 44,205
  • 11
  • 83
  • 107
pierrant
  • 320
  • 1
  • 4
  • This helped to solve problem with ClassNotFoundExeption, but I have such errors yet: `Error | 2014-09-01 16:42:23,510 [localhost-startStop-1] ERROR pool.ConnectionPool - Una ble to create initial connections of pool. Message: Network error IOException: Connection refused: connect` – AlexandrM Sep 01 '14 at 13:01
  • 1
    Have you enabled TCP connexions in your SQL Server? See for instance: http://stackoverflow.com/questions/9138172/enable-tcp-ip-remote-connections-to-sql-server-express-already-installed-databas – pierrant Sep 01 '14 at 13:06
  • Yes. TCP connections in my Server is enebled – AlexandrM Sep 01 '14 at 13:37
  • Then it must be the url. Try something like `url = "jdbc:jtds:sqlserver://127.0.0.1/MyGrailsDatabase"` and make sure that username and password are valid. – pierrant Sep 01 '14 at 14:09
  • I haven't done Grails in a while, but this was my url: `url = "jdbc:jtds:sqlserver://127.0.0.1:1433;databaseName=grailsDb"` I'm not sure if you need to specify the port. – L_7337 Sep 02 '15 at 12:41