我在从 C# ADO.Net 程序连接到 DB2 iSeries 数据库时遇到问题。
我可以使用 ClientAccess“从 iSeries 传输数据”工具从 Windows 机器连接到 DB2/iSeries,并具有以下设置:
IBM i name: 192.168.0.1
User: VCT130
Passwd: pass
File name: CHGDG#VL/AREA(AREA)
它检索 23 条记录。
我正在尝试从一个简单的 C# 程序访问相同的数据,总结如下:
using IBM.Data.DB2.iSeries;
string conStr= "DataSource=192.168.0.1;UserID=VCT130;Password=pass;Naming=System;LibraryList=QIWS,CHGDG#VL,CHNNL#VL,CHVAT#VL;DefaultCollection=QIWS;" ;
string sql= "SELECT * from CHGDG#VL/Area;" ; // ALSO TRIED ...from CHGDG#VL/Area(AREA);
iDB2Connection conn = new iDB2Connection(conStr);
iDB2Command cmd = new iDB2Command(sql, conn);
iDB2DataReader rdr = cmd.ExecuteReader();
conn 和 cmd 对象创建正常,但 ExecuteReader() 调用失败,并显示:
Unhandled Exception: System.InvalidOperationException: The operation cannot complete because the connection is not valid.
at IBM.Data.DB2.iSeries.iDB2Command.verifyConnection()
at IBM.Data.DB2.iSeries.iDB2Command.ExecuteDbDataReader(CommandBehavior behavior)
at IBM.Data.DB2.iSeries.iDB2Command.ExecuteReader()
at test04.DBDB2.read() in
c:\Users\mikeb\projs\ClassLibrary1\ClassLibrary1\DBDB2.cs:line 27
我的第 27 行是对 cmd.ExecuteReader() 的调用
请问有什么想法吗?
11 月 19 日进一步的想法:
[请原谅任何笨拙的礼仪,我是这里的新海报]
- 我错过了什么吗?我认为这里只有两件事会
出错:- 我的代码。不,太简单了,由@MikeWills 的帖子验证
- 我的连接字符串
- 或者还能有别的东西吗?
- 重新 IBM.Data.DB2.iSeries.iDB2Command.verifyConnection()
这里有人可以访问代码来说明此方法的作用以及可能导致它失败的原因吗?