2
votes

I am new to Play framework. I have problem in connection of sql server from play 2.4.6.

File application.conf as bellow

db.default.url="jdbc:jtds:sqlserver://127.0.0.1:1433/DBNAME",
db.default.driver=net.sourceforge.jtds.jdbc.Driver,
db.default.user=sa,
db.default.pass=pass 

I added jtds-1.2.6 jar in the lib and libexec folders.

build.sbt file as below.

libraryDependencies ++= Seq(
  javaJdbc,
  "net.sourceforge.jtds" % "jtds" % "1.2.6",
  cache,
  javaWs
)

fork in run := true

But when i go to browser at http://localhost:9000/ i get following error

Cannot connect to database [default]

please help me any one.

Following is detailed Exception:

! @700ahko28 - Internal server error, for (GET) [/] -> application -

play.api.Configuration$$anon$1: Configuration error[Cannot connect to database [default]] at play.api.Configuration$.configError(Configuration.scala:154) at play.api.Configuration.reportError(Configuration.scala:806) at play.api.db.DefaultDBApi$$anonfun$connect$1.apply(DefaultDBApi.scala:48) at play.api.db.DefaultDBApi$$anonfun$connect$1.apply(DefaultDBApi.scala:42) at scala.collection.immutable.List.foreach(List.scala:381) at play.api.db.DefaultDBApi.connect(DefaultDBApi.scala:42) at play.api.db.DBApiProvider.get$lzycompute(DBModule.scala:72) at play.api.db.DBApiProvider.get(DBModule.scala:62) at play.api.db.DBApiProvider.get(DBModule.scala:58) at com.google.inject.internal.ProviderInternalFactory.provision(ProviderInternalFactory.java:81) Caused by: play.api.Configuration$$anon$1: Configuration error[Exception during pool initialization: HikariPool-0 - Connection is not available, request timed out after 30001ms.]

2
Check the complete stack tracecchantep
I think the comma in the end of each line in application.conf is too much.Kris

2 Answers

1
votes

I was having a similar problem with a new Play!2 app that I created in IntelliJ 2016. I copied the configuration from an existing (older) application accessing the same development server, and was working. But when I ran it in the new project it no longer worked and produced a very similar stack trace.

After much Googling and multiple configuration variations I discovered this link: https://github.com/brettwooldridge/HikariCP/issues/497. When I tried adding the following tot he application.config suddenly everything worked:

db.default.hikaricp.connectionTestQuery="SELECT 1"
0
votes

The correct properties to use are username instead of user and password instead of pass.

The properties are here

Also, you don't need commas in your application.conf file. Once you have mentioned jtds in libraryDependencies you don't need to manually put them in lib or somewhere else. SBT will pull them and put them in classpath.