如何在h2 sqlserver模拟器中创建dbo架构?

时间:2014-08-13 01:33:53

标签: scala h2 slick

我得到了

JdbcSQLException: Schema "dbo" not found; 
SQL statement: create table "dbo"."TableName"

在针对h2 sqlserver模拟器运行一些样板sql时(即使用配置设置:

db.default.slickdriver=com.typesafe.slick.driver.ms.SQLServerDriver
db.default.driver=net.sourceforge.jtds.jdbc.Driver
db.default.url="jdbc:h2:file:~/data/test1;MODE=MSSQLServer"

运行以下内容:

Database.forDataSource(DB.getDataSource()) 
   withSession {

我尝试过创建架构:

  Database.forDataSource(DB.getDataSource())     
    withSession {
    implicit session => 
       Q.updateNA("CREATE SCHEMA \"dbo\" AUTHORIZATION sa;")
  }

但似乎没有做到这一点(或报告错误消息)。我错过了什么吗?


仍无法以编程方式创建架构。能够通过h2控制台轻松创建它,使用与上面完全相同的查询。


play.api.UnexpectedException: Unexpected exception[JdbcSQLException: Schema "dbo" not found; SQL statement:
create table "dbo"."TestTable" ("TestTableId" CHAR(36))
at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$1$$anonfun$1.apply(ApplicationProvider.scala:148) ~[play_2.10-2.2.3.jar:2.2.3]
    at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$1$$anonfun$1.apply(ApplicationProvider.scala:112) ~[play_2.10-2.2.3.jar:2.2.3]
    at scala.Option.map(Option.scala:145) ~[scala-library-2.10.4.jar:na]
    at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$1.apply(ApplicationProvider.scala:112) ~[play_2.10-2.2.3.jar:2.2.3]
    at play.core.ReloadableApplication$$anonfun$get$1$$anonfun$apply$1.apply(ApplicationProvider.scala:110) ~[play_2.10-2.2.3.jar:2.2.3]
    at scala.util.Success.flatMap(Try.scala:200) ~[scala-library-2.10.4.jar:na]
Caused by: org.h2.jdbc.JdbcSQLException: Schema "dbo" not found; SQL statement:
create table "dbo"."TestTable" ("TestTableId" CHAR(36))
at org.h2.message.DbException.getJdbcSQLException(DbException.java:329) ~[h2-1.3.172.jar:1.3.172]
    at org.h2.message.DbException.get(DbException.java:169) ~[h2-1.3.172.jar:1.3.172]
    at org.h2.message.DbException.get(DbException.java:146) ~[h2-1.3.172.jar:1.3.172]
    at org.h2.command.Parser.getSchema(Parser.java:613) ~[h2-1.3.172.jar:1.3.172]
    at org.h2.command.Parser.getSchema(Parser.java:620) ~[h2-1.3.172.jar:1.3.172]
    at org.h2.command.Parser.parseCreateTable(Parser.java:5254) ~[h2-1.3.172.jar:1.3.172]

1 个答案:

答案 0 :(得分:1)

请避免使用此表单的数据库URL(jdbc:h2:file:data/test1),因为这是相对于当前工作目录的(并且工作目录可以更改)。请改为使用jdbc:h2:/absolute/pathjdbc:h2:~/data(相对于当前用户主目录)。

如果您对create table "dbo"."TableName"使用双引号,则还需要对create schema使用双引号:

create schema "dbo" authorization sa