Reputation: 2095
I am having difficulty connecting to our MSSQL database using Slick.
I know that I have to use Slick Extensions and have done so. Here is an excerpt from our build
lazy val thirdPartyDependencies = Seq(
...
"com.typesafe.slick" %% "slick-extensions" % "3.1.0",
"com.typesafe.play" %% "play-slick" % "1.1.0",
"com.typesafe.slick" %% "slick-codegen" % "3.1.0" % "compile"
)
lazy val allResolvers = Seq(
"Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/",
"sonatype-releases" at "https://oss.sonatype.org/content/repositories/releases/",
"Typesafe Releases" at "http://repo.typesafe.com/typesafe/maven-releases/"
)
Here's the application.conf configuration for Slick
#Slick configuration.
slick.dbs.default.driver=com.typesafe.slick.driver.ms.SQLServerDriver
slick.dbs.default.db.driver=com.microsoft.sqlserver.jdbc.SQLServerDriver
slick.dbs.default.db.url=${?db.default.url}
slick.dbs.default.db.user=${?sql_user}
slick.dbs.default.db.password=${?sql_password}
I built the Table definition using the SourceCodeGenerator
tool without issues. Here's the code that connects to the database:
val dbConfig = DatabaseConfigProvider.get[JdbcProfile](Play.current)
I don't have any compile time problems but run into the following stack trace when I run the code:
[error] play.api.db.slick.DefaultSlickApi - Failed to create Slick database config for key default.
slick.SlickException: Error getting instance of Slick driver "com.typesafe.slick.driver.ms.SQLServerDriver"
at slick.backend.DatabaseConfig$.forConfig(DatabaseConfig.scala:65) ~[slick_2.11-3.1.0.jar:na]
at play.api.db.slick.DefaultSlickApi$DatabaseConfigFactory.create(SlickApi.scala:89) [play-slick_2.11-1.1.0.jar:1.1.0]
...
Caused by: java.lang.InstantiationException: com.typesafe.slick.driver.ms.SQLServerDriver
at java.lang.Class.newInstance(Class.java:427) ~[na:1.8.0_45]
at slick.backend.DatabaseConfig$.forConfig(DatabaseConfig.scala:63) ~[slick_2.11-3.1.0.jar:na]
... 22 common frames omitted
Caused by: java.lang.NoSuchMethodException: com.typesafe.slick.driver.ms.SQLServerDriver.<init>()
at java.lang.Class.getConstructor0(Class.java:3082) ~[na:1.8.0_45]
at java.lang.Class.newInstance(Class.java:412) ~[na:1.8.0_45]
... 23 common frames omitted
I'm completely new to Slick. We have a commercial typesafe license so I figure we should probably be using some of the slick features provided therein. Thank you for your help.
Upvotes: 2
Views: 881
Reputation: 521178
There is a problem in your application.conf
configuration file. Try putting in a trailing $
at the end of the driver name to tell Slick to refer to it as an object:
slick.dbs.default.driver = "com.typesafe.slick.driver.ms.SQLServerDriver$"
Please read this SO post for more information.
Upvotes: 2