linux连接db2指定Schema连接,在连接字符串中为DB2查询指定模式/实例(Specify schema/instance for DB2 query in connection string...

在使用ODBC连接DB2时,可通过在连接字符串中添加`CurrentSchema=mySCHEMA`来指定默认模式,避免在查询中每次都指定Schema。错误[42S02]表明名称未定义,可能是因为缺少Schema指定。

在连接字符串中为DB2查询指定模式/实例(Specify schema/instance for DB2 query in connection string)

我试图将默认架构/实例指定为连接字符串(或特定命令)的一部分,因此它不需要是查询的一部分。

OdbcConnection conn = new OdbcConnection("Driver={IBM DB2 ODBC DRIVER}; Database=myDB; Hostname=myHostName; Port=myPort; Protocol=TCPIP; Uid=myID; Pwd=myPW;");

OdbcCommand comm = new OdbcCommand("select count(*) from customers", conn);

conn.Open();

var value = comm.ExecuteScalar();

conn.Close();

不幸的是,这失败了,错误:

错误[42S02] [IBM] [CLI驱动程序] [DB2] SQL0204N myID .customers是未定义的名称。 SQLSTATE = 42704。

请注意,它使用的是模式/实例所在的myID 。 如果我指定架构/实例明确:

OdbcCommand comm = new OdbcCommand("select count(*) from mySCHEMA.customers", conn);

它按预期工作。 我想将mySCHEMA指定为连接字符串的一部分,类似于使用MS SQL Server时的“初始目录”。

经过一系列的实验和谷歌搜索,我似乎无法弄明白。 有任何想法吗?

I am trying to specify the default schema/instance as part of a connection string (or specific command) so it does not need to be part of the query.

OdbcConnection conn = new OdbcConnection("Driver={IBM DB2 ODBC DRIVER}; Database=myDB; Hostname=myHostName; Port=myPort; Protocol=TCPIP; Uid=myID; Pwd=myPW;");

OdbcCommand comm = new OdbcCommand("select count(*) from customers", conn);

conn.Open();

var value = comm.ExecuteScalar();

conn.Close();

Unfortunately this fails with the error:

ERROR [42S02] [IBM][CLI Driver][DB2] SQL0204N myID.customers is an undefined name. SQLSTATE=42704.

Notice it's using myID where the Schema/Instance should be. If I specify the schema/instance explicity:

OdbcCommand comm = new OdbcCommand("select count(*) from mySCHEMA.customers", conn);

it works as expected. I'd like to specify mySCHEMA as part of the Connection String, similar to "Initial Catalog" when using MS SQL Server.

After a bunch of experimentation and googling, I can't seem to figure it out. Any ideas?

原文:https://stackoverflow.com/questions/10727575

更新时间:2019-09-30 23:28

最满意答案

哇,这个很明显。 我只需要连接字符串中的CurrentSchema = mySCHEMA。

出于某种原因,我在通过http://www.connectionstrings.com/ibm-db2 (尝试各种变体,如Schema,Default Schema等)后立即没有连接该点。 希望这有助于将来......

Wow, this one was obvious. I just need CurrentSchema=mySCHEMA in the connection string.

For some reason I didn't connect that dot right away after working through http://www.connectionstrings.com/ibm-db2 (tried all sorts of variations like Schema, Default Schema, etc). Hopefully this helps someone in the future...

2012-05-23

相关问答

几个原因。 它不是相同的DB和/或架构。 该表具有行级安全性(DB2具有此功能),并且登录的JDBC用户对于未返回的用户没有足够的权限。 在未提交的同一事务中插入并选择了那么多行。 Several causes. It's not the same DB and/or schema. The table has row-level security (DB2 has this feature) and the logged-in JDBC user hasn't sufficient rights

...

我的办公室版本是标准2013,其他数据库的导入数据不支持。 My office edition is standard 2013 , which is not supported for import data from other database.

错误信息是不言自明的: 无效的数据库URL语法 URL中不能有任何空格,并且键 - 值对以分号分隔,而不是逗号分隔。 请注意,您也必须在最后一个值后面加上分号。 jdbc:db2://dxxx_xxx.xxx.com:5000/XXXXX:deferPrepares=false;username=NNNNN;

详细信息可以在手册中找到。 The error message is pretty self-explanatory: Invalid database URL syntax You mu

...

关闭连接后,您必须打开一个新连接(使用您已经使用的代码)才能再次访问数据库。 在每个“逻辑”查询组之后关闭连接是正确的。 Once you've closed a connection you have to open a new one (using the code you're already using) in order to access to the DB again. It is correct to close the connection after each 'logic'

...

感兴趣的人的临时解决方法:在ebean.properties中,设置 ebean.databaseSequenceBatchSize=1

Temporary workaround for those interested: in ebean.properties, set ebean.databaseSequenceBatchSize=1

原来我安装了10.5.5驱动程序,但未能将其设置为默认值。 运行“默认DB2和数据库客户端接口选择向导”(仅通过在开始菜单中搜索找到)并将新的设置为默认值后,它工作正常 Turns out I had installed the 10.5.5 driver but it failed to be set as the default. After running the "Default DB2 and Database Client Interface Selection wizard" (fo

...

哇,这个很明显。 我只需要连接字符串中的CurrentSchema = mySCHEMA。 出于某种原因,我在通过http://www.connectionstrings.com/ibm-db2 (尝试各种变体,如Schema,Default Schema等)后立即没有连接该点。 希望这有助于将来...... Wow, this one was obvious. I just need CurrentSchema=mySCHEMA in the connection string. For som

...

好的,鉴于上面的注释,您无法直接导入DB2的容器文件(DAT,LRG或其他任何东西)。 您需要CSV或同等产品。 是的,获得此功能的一种方法是在实时DB2数据库上运行EXPORT实用程序。 HTH! OK, given the comment above, you can't import DB2's container files (DAT, LRG, or anything else) directly. You need a CSV or equivalent. Yes, one way t

...

当对象不存在时抛出SQLSTATE 42704。 FROM子句引用表名,而不是DB。 表名可能是合格的或不合格的; 从技术上讲,限定表名称可以包含远程数据库名称。 你说这个有效: SELECT *

FROM SYSCAT.COLUMNS

WHERE TABSCHEMA= 'GGA' AND TABNAME= 'VIRTUALMACHINE'

fetch first 10 rows only

请注意,正在查询SYSCAT模式中的COLUMNS表。 所以以下应该有效: select *

fro

...

我怀疑~db2inst1/sqllib中的一些文件权限(特别是~db2inst1/sqllib/security/db2ckpw )已被更改。 您可以使用db2iupdt实用程序解决此问题(以及其他问题)。 在实例停止时,您需要以root用户身份运行它。 文档: db2iupdt - 更新实例命令 Everyone, thank you so much for your ideas and suggestions! I finally managed to solve this problem t

...

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值