4

When I try to use the new proprietary MS SQL driver, I get an exception which boils down to a ClassNotFound for the driver class.

I include both slick and slick-extensions:

"com.typesafe.slick" %% "slick" % "2.0.1",
"com.typesafe.slick" %% "slick-extensions" % "2.0.1"

Example use:

import com.typesafe.slick.driver.ms.SQLServerDriver.simple._

Database.forURL(url="jdbc:sqlserver://hostname:1433;databaseName=thedb1", driver = "com.typesafe.slick.driver.ms.SQLServerDriver", user="user", password="password" ) withSession { ...

Exception:

Ultimately, ClassNotFound for com.typesafe.slick.driver.ms.SQLServerDriver.

  • https://github.com/freekh/play-slick seems to be the answer. – FullTimeCoderPartTimeSysAdmin Apr 01 '14 at 23:21
  • To get Slick 2.0 connected to Microsoft SQL Server within Playframework 2.2.x, use play-slick >= 0.6.0 (https://github.com/freekh/play-slick) and the JDBC SQL driver from microsoft (com.microsoft.sqlserver.jdbc.SQLServerDriver). play-slick has a sample application: https://github.com/freekh/play-slick/blob/master/samples/computer-database This question covers the correct driver to use for sqlserver: http://stackoverflow.com/questions/21045561/scala-slick-connect-to-mssql-server – FullTimeCoderPartTimeSysAdmin Apr 01 '14 at 23:55
  • Apparantly driver config needs to specify both the MS JDBC driver and the one in slick extensions? db.default.slickdriver=com.typesafe.slick.driver.ms.SQLServerDriver db.default.driver=com.microsoft.sqlserver.jdbc.SQLServerDriver – FullTimeCoderPartTimeSysAdmin Apr 01 '14 at 23:57
  • It turns out you can use the open source jTDS driver as well. (By setting db.default.driver to net.sourceforge... and leaving db.default.slickdriver set to the Slick driver.) – FullTimeCoderPartTimeSysAdmin Apr 02 '14 at 16:07
  • https://github.com/freekh/play-slick/blob/ffe2a505287bc3b76c4cf95ddb9105a8ab0ae92a/src/main/scala/play/api/db/slick/Config.scala#L11 – FullTimeCoderPartTimeSysAdmin Apr 02 '14 at 16:08
  • Asked about it here https://github.com/freekh/play-slick/issues/151 – Andre Apr 30 '14 at 05:54
  • @Andre -- thanks. I figured this out but don't have the rep to answer my own question. If you want to post an answer I'll accept it. (To help future googlers.) – FullTimeCoderPartTimeSysAdmin Apr 30 '14 at 17:22

1 Answers1

3

I ran across the same issue and was able to solve it by defining the following lines in the application.conf file (thanks to the help from the play-slick contributors here):

db.default.slickdriver=com.typesafe.slick.driver.ms.SQLServerDriver
db.default.driver=com.microsoft.sqlserver.jdbc.SQLServerDriver

Alternatively, you could use the jTDS driver from sourceforge like listed in the question's comments.

db.default.slickdriver=com.typesafe.slick.driver.ms.SQLServerDriver
db.default.driver=net.sourceforge.jtds.jdbc.Driver

I ended up doing the first option, which meant downloading the unmanaged dependency sqljdbc4.jar(available here) and placing it on the {play app root}/lib directory. Since the jTDS driver is available as a library dependency for build.sbt, I'd suggest trying that one first.

Andre
  • 790
  • 2
  • 9
  • 23
  • Minor additions: be sure to use play.api.db.slick.DB instead of play.api.db.DB, as well as the convenience class DBAction instead of Action in any controller methods that access the database. – FullTimeCoderPartTimeSysAdmin May 01 '14 at 16:50
  • What's the right solution if doing this outside of Play? I'm just pulling in slick + slick-extensions. – anshumans Jul 31 '14 at 00:51