Slick can't connect to SQL Server Database - scala

I'm running a Scala-Play back end and i'm trying to get slick 2.1.0 to connect to my microsoft sql server database. However i'm constantly getting "Can't Connect To Database" every-time i load up.
These are my settings i'm running slick 2.1.0
slick-extensions 2.1.0 gives me a "unknown artifact" in my IDE
libraryDependencies ++= Seq(
cache, ws, filters, jdbc, evolutions,
"com.typesafe.slick" %% "slick-extensions" % "2.1.0",
"com.typesafe.slick" %% "slick" % "2.1.0"
)
My Application.conf.
db.default {
driver = "com.typesafe.slick.driver.ms.SQLServerDriver"
url = """jdbc:sqlserver://SKYNET\DEV:40000"""
username = "XXX"
password = "XXXXXXXX"
}
Any help or push in the right direction would be greatly appreciated. The JDBC connection url is 100% not the problem because iv'e tested that JDBC string in my IDE to connect.
I think its because i can't get the driver from slick-extensions.
EDIT: Have the resolver in my built.sbt aswell.
EDIT UPDATE: I think after some Github slick reading iv'e progressed the new problem is "Cannot load Driver[Driver [com.microsoft.sqlserver.jdbc.SQLServerDriver] cannot be instantiated.]"
Updated Code:
db.default {
slickdriver = "com.typesafe.slick.driver.ms.SQLServerDriver"
driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver"
url = "jdbc:sqlserver://SKYNET\\DEV:40000"
username = "XXXXX"
password = "XXXXXXXXXXXXXXXXXXXX"
}

"com.microsoft.sqlserver" % "mssql-jdbc" % "6.2.1.jre8",
Added into my libraryDependencies in SBT fixed it.

Related

Trying to connect postgresql heroku with play

I'm trying to use heroku postgresql with play framework (version 2.5.9) but it doesn't work...
build.sbt
libraryDependencies ++= Seq(
javaJdbc,
cache,
javaWs,
javaJpa,
"org.webjars" % "bootstrap" % "2.3.1",
"org.hibernate" % "hibernate-entitymanager" % "5.2.3.Final",
"postgresql" % "postgresql" % "9.1-901-1.jdbc4"
)
conf/application.conf
ebean.default = ["models.*"]
db.default.driver=org.postgresql.Driver
db.default.url="postgres://ambpfzhcrpupmx:PeSnt07zQFVWKQrsqcRd1GzW6I#ec2-54-227-245-197.compute-1.amazonaws.com:5432/d4i5fck68498ce"
default.username = hereMyUserNameFromHeroku
default.password = "hereMyPassNameFromHeroku"
I obtain :
Caused by: org.postgresql.util.PSQLException: FATAL: no pg_hba.conf entry for host "78.192.102.83", user "ambpfzhcrpupmx", database "d4i5fck68498ce", SSL off
I dont' understand why...
I'm trying to add "?ssl=true" at the end of my url but it doesn't work too... I obtain :
Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
Anybody can help me plz ? Thank :)
First, reset your Postgres username and password because you've posted them publicly and anyone can access your database now. Run this command:
$ heroku pg:credentials DATABASE --reset
Then change your conf/application.conf to use the JDBC_DATABASE_URL environment variable as per the Play Framework documentation.
db.default.url=${?JDBC_DATABASE_URL}
db.default.username=${?JDBC_DATABASE_USERNAME}
db.default.password=${?JDBC_DATABASE_PASSWORD}
The underlying problem is that your database URL does not enable SSL, and your Postgres JDBC dependency is too old for it to be turned on automatically. I recommend updating to this:
"org.postgresql" % "postgresql" % "9.4.1211"

Play Framework trying to access DB with windows username

I have a db.conf which looks like this in the conf folder:
db.default.driver=org.postgresql.Driver
db.default.url="jdbc:postgresql://62.210.145.112/babybets"
db.default.username=postgres
db.default.password="my_password"
It is included in the application.conf:
include "db.conf"
Infos are definitely correct, as I use this very same jdbc connection string, user/pass to connect the Intellij DB view to the database.
When I try to access any page, I get an error:
play.api.Configuration$$anon$1: Configuration error[Cannot connect to database [default]]
at play.api.Configuration$.play$api$Configuration$$configError(Configuration.scala:94) ~[play_2.10-2.3.8.jar:2.3.8]
at play.api.Configuration.reportError(Configuration.scala:743) ~[play_2.10-2.3.8.jar:2.3.8]
at play.api.db.BoneCPPlugin$$anonfun$onStart$1.apply(DB.scala:247) ~[play-jdbc_2.10-2.3.2.jar:2.3.2]
at play.api.db.BoneCPPlugin$$anonfun$onStart$1.apply(DB.scala:238) ~[play-jdbc_2.10-2.3.2.jar:2.3.2]
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244) ~[scala-library-2.10.5.jar:na]
Caused by: org.postgresql.util.PSQLException: FATAL: password authentication failed for user "John"
at org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:293) ~[postgresql-9.1-901-1.jdbc4.jar:na]
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:108) ~[postgresql-9.1-901-1.jdbc4.jar:na]
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:66) ~[postgresql-9.1-901-1.jdbc4.jar:na]
at org.postgresql.jdbc2.AbstractJdbc2Connection.<init>(AbstractJdbc2Connection.java:125) ~[postgresql-9.1-901-1.jdbc4.jar:na]
at org.postgresql.jdbc3.AbstractJdbc3Connection.<init>(AbstractJdbc3Connection.java:30) ~[postgresql-9.1-901-1.jdbc4.jar:na]
In the above you can see it tries to connect to the database using my windows login "John".
I went through the project with agent Ransack and tried the following (case insensitive) regex:
[^\\]john[^\\]
It only matches with the above error log.
Question: Why is play using my windows login to Connect DB? How to prevent that ?
Just for info my build.sbt looks like this:
name := "babyBets2"
version := "1.0"
lazy val `babybets2` = (project in file(".")).enablePlugins(PlayScala)
scalaVersion := "2.10.5"
libraryDependencies ++= Seq( cache , ws )
libraryDependencies ++= Seq("postgresql" % "postgresql" % "9.1-901-1.jdbc4",
"com.typesafe.play" %% "play-slick" % "0.8.0",
"ws.securesocial" %% "securesocial" % "2.1.4" )
unmanagedResourceDirectories in Test <+= baseDirectory ( _ /"target/web/public/test" )
Ok this is crazy, there is a difference between Play versions:
https://www.playframework.com/documentation/2.4.x/ScalaDatabase
https://www.playframework.com/documentation/2.3.x/ScalaDatabase
db.default.username=postgres
vs
db.default.user=postgres
So apparently, if no user is provided, play displays no useful error messages and tries to connect you with windows login!

How to configure HikariCP for Slick 3.0.0 RC1 on Typesafe conf

I have a Play Application based on the play-scala Typesafe template (Play Scala Seed), and tried to add Slick 3.0.0 to the project and connect to a PostgreSQL database.
First I added the dependencies to build.sbt:
libraryDependencies ++= Seq(
"com.typesafe.slick" %% "slick" % "3.0.0-RC1",
"postgresql" % "postgresql" % "9.1-901.jdbc4"
)
Then added the database configuration on application.conf:
brDb = {
dataSourceClass = org.postgresql.ds.PGSimpleDataSource
url = "jdbc:postgresql://localhost:5432/test"
user = "postgres"
password = "postgres"
numThreads = 10
}
Note that I haven't disabled explicitly the pooling, so it is enabled by default, and will try to use HikariCP, because as of Slick 3.0.0 RC1, HikariCP support exists and pooling using it is enabled by default.
And in my DAO object, tried to get the database connection like this:
Database.forConfig("brDb")
When I run the app using activator run, I get this error:
RuntimeException: java.lang.NoClassDefFoundError:
com/zaxxer/hikari/HikariConfig
Then I tried adding HikariCP as a dependency in build.sbt:
libraryDependencies ++= Seq(
// ...
"com.zaxxer" % "HikariCP" % "2.3.3",
// ...
)
Cleaned and recompiled the app using activator clean compile, and runned it again, but I get another error:
RuntimeException: java.lang.UnsupportedClassVersionError: com/zaxxer/hikari/HikariConfig
I think I am missing some configuration, but I am not sure and have not found more info about it. How should I set up the configuration to get the connection pool working?
That error means that the HikariCP package is compiled for a JRE newer than the one you#re running on. And in fact, if you look at the homepage, you'll see that the version you are using is this:
Java 8 maven artifact:
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>2.3.5</version>
<scope>compile</scope>
</dependency>
I suppose you're running on Java 7. For that, add the following to your build.sbt:
libraryDependencies ++= Seq(
"com.zaxxer" % "HikariCP-java6" % "2.3.3",
)
Btw, I have found out that the configuration structure that you specified above does not actually work as of Slick 3.0.0. What worked for me was to specify the database configuration as described in the documentation http://slick.typesafe.com/doc/3.0.0/database.html#using-typesafe-config, otherwise Slick will assume some default values for the configuration. I'm mainly talking about the "properties" field.
So something like this should work:
mydb = {
dataSourceClass = "org.postgresql.ds.PGSimpleDataSource"
properties = {
serverName = "postgresdb"
portNumber = "5432"
databaseName = "mydb"
user = "myuser"
password = "secret"
}
numThreads = 10
}

Play 2.3.5 and ReactiveMongo: MongoError['No primary node is available!']

I recently upgraded Play to version 2.3.5 and try to use it with ReactiveMongo. However everytime I try to read data from mongoDB an exception occurred. This is my build.sbt:
name := """ReactiveMongoRestExample"""
version := "1.0-SNAPSHOT"
lazy val root = (project in file(".")).enablePlugins(PlayScala)
scalaVersion := "2.11.1"
libraryDependencies ++= Seq(
jdbc,
anorm,
cache,
ws,
"org.reactivemongo" %% "play2-reactivemongo" % "0.10.5.0.akka23"
)
This is the stacktrace:
play.api.Application$$anon$1: Execution
exception[[PrimaryUnavailableException$: MongoError['No primary node
is available!']]] at
play.api.Application$class.handleError(Application.scala:296)
~[play_2.11-2.3.5.jar:2.3.5] at
play.api.DefaultApplication.handleError(Application.scala:402)
[play_2.11-2.3.5.jar:2.3.5] at
play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$14$$anonfun$apply$1.applyOrElse(PlayDefaultUpstreamHandler.scala:205)
[play_2.11-2.3.5.jar:2.3.5] at
play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$14$$anonfun$apply$1.applyOrElse(PlayDefaultUpstreamHandler.scala:202)
[play_2.11-2.3.5.jar:2.3.5] at
scala.runtime.AbstractPartialFunction.apply(AbstractPartialFunction.scala:36)
[scala-library-2.11.2.jar:na] Caused by:
reactivemongo.core.actors.Exceptions$PrimaryUnavailableException$:
MongoError['No primary node is available!'] at
reactivemongo.core.actors.Exceptions$PrimaryUnavailableException$.(actors.scala)
~[reactivemongo_2.11-0.10.5.0.akka23.jar:0.10.5.0.akka23] at
reactivemongo.core.actors.MongoDBSystem$$anonfun$pickChannel$4.apply(actors.scala:508)
~[reactivemongo_2.11-0.10.5.0.akka23.jar:0.10.5.0.akka23] at
reactivemongo.core.actors.MongoDBSystem$$anonfun$pickChannel$4.apply(actors.scala:508)
~[reactivemongo_2.11-0.10.5.0.akka23.jar:0.10.5.0.akka23] at
scala.Option.getOrElse(Option.scala:120)
~[scala-library-2.11.2.jar:na] at
reactivemongo.core.actors.MongoDBSystem.pickChannel(actors.scala:508)
~[reactivemongo_2.11-0.10.5.0.akka23.jar:0.10.5.0.akka23]
MongoDB works fine. I'm able to retrieve data with the commandline tool and IntelliJ.
I pushed the code to github
Maybe someone knows the issue and can help me? That would be awesome
Same issue though updated to Play 2.3.8 with same rx mongo plugin. Mongodb backed works fine under mongo shell as does mongo explorer in intellij idea 14.
Using mongodb.uri in application.conf:
mongodb.uri = "mongodb://pxxxxxxxx:pxxxxxxxx#berne:27017/playdb"
Digging deeper on assumption this is a configuration issue.
Henry
It's probably unable to start the Mongo server.
Go to your /bin folder and run mongo.
You might have too little room available on your temporary folder.
try running : mongo --smallfiles
I had this error because I tried to connect to the db with an unknown user. Creating the user resolved the error.

Postgres + Play 2.2.1 Java - Driver not found : [ org.postgresql.Driver ]

I'm trying to connect the sample 'computer-database-jpa' to postgres , but I cant.
https://github.com/playframework/playframework/tree/master/samples/java/computer-database-jpa
Could you help me?
My steps:
add jar (build path> configure build path > add external jars ... )
add to build.sbt: "postgresql" % "postgresql" % "9.3-1100.jdbc4"
add to application.conf:
db.default.driver=org.postgresql.Driver
db.default.url=" jdbc:postgresql://localhost:5432/teste "
db.default.user="postgres"
db.default.password="postgre"
Result:
Browser message: Driver not found : [ org.postgresql.Driver ]
Where is the problem ?
PostgreSQL artifacts have moved to a new group ID org.postgresql.
"org.postgresql" % "postgresql" % "9.3-1100-jdbc4"