PlayFramework MSSQL数据库错误

时间:2012-02-09 13:45:37

标签: playframework

我试图在我的application.conf

中使用Play Framework的MSSQL服务器
    db.url=jdbc:microsoft:sqlserver://localhost\SQL2008:1433;DatabaseName=testDB
    db.driver=com.microsoft.jdbc.sqlserver.SQLServerDriver
    db.user=sa
    db.pass=sa

得到以下错误

Database error
A database error occured : Cannot connected to the database, [Microsoft][SQLServer    
2000 Driver for JDBC]Error establishing socket.

play.exceptions.DatabaseException: Cannot connected to the database, [Microsoft]   
[SQLServer 2000 Driver for JDBC]Error establishing socket.
at play.db.DBPlugin.onApplicationStart(DBPlugin.java:132)
at play.plugins.PluginCollection.onApplicationStart(PluginCollection.java:425)
at play.Play.start(Play.java:495)
at play.Play.detectChanges(Play.java:599)
at play.Invoker$Invocation.init(Invoker.java:186)
at Invocation.HTTP Request(Play!)
 Caused by: java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Error    
 establishing socket.
at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSConnection.<init>(Unknown Source)
at com.microsoft.jdbc.sqlserver.SQLServerImplConnection.open(Unknown Source)
at com.microsoft.jdbc.base.BaseConnection.getNewImplConnection(Unknown Source)

我已将sqljdbc4.jar添加到lib文件夹中。 甚至尝试过使用mssqlserver.jar,msutil.jar,msbase.jar

4 个答案:

答案 0 :(得分:6)

对于某些人来说可能很有用,他们一直在寻找MSSQL。

首先下载jtds

将jtds jar文件复制到

   play-1.2.3\framework\lib

以及您的应用程序li​​b文件夹

重新开始播放

在你的application.conf

   # If you need a full JDBC configuration use the following :
   db.url=jdbc:jtds:sqlserver://localhost:1433/testDB;instance=SQL2008
   db.driver=net.sourceforge.jtds.jdbc.Driver
   db.user=sa
   db.pass=sa

开始播放:)

Play2更新

向您的Build.scala添加播放依赖项

 val appDependencies = Seq(
    "net.sourceforge.jtds" % "jtds" % "1.2"
  )

Play2中的conf文件发生了变化......

   db.default.url="jdbc:jtds:sqlserver://localhost:1433/testDB;instance=SQL2008"
   db.default.driver=net.sourceforge.jtds.jdbc.Driver
   db.default.user=sa
   db.default.pass=sa

restart play SBT将为您下载依赖项。开始玩:)

答案 1 :(得分:0)

看起来无法连接到在localhost:1433端口上运行的ms sql server。您可能会检查以下几点:

  1. 您是否在localhost上运行了ms sql server?

  2. 您的ms sql服务器上是否启用了TCP / IP?

  3. 你有ms sql server收听1433端口吗?

  4. 您可以按http://support.microsoft.com/kb/313178来诊断问题

答案 2 :(得分:0)

尝试从您的网址中删除SQL2008部分

db.url=jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=testDB

答案 3 :(得分:0)

对于play framework 2.5以下是我的配置

 db.default.driver=net.sourceforge.jtds.jdbc.Driver
 db.default.url="jdbc:jtds:sqlserver://ipaddress:1433/TESTDB"
 db.default.username=USER
 db.default.password="Password"
 db.default.hikaricp.connectionTestQuery="SELECT 1"

并添加了一个依赖

val appDependencies = Seq(
    "net.sourceforge.jtds" % "jtds" % "1.2"
  )

此外,如果你使用的是Ebean,那么在plugin.sbt中添加ebean pluging为

addSbtPlugin("com.typesafe.sbt" % "sbt-play-ebean" % "1.0.0")

最后在conf as

ebean.default = ["models.*"]