I'm having problems connecting to a DB2 iSeries database from a C# ADO.Net program.

I can connect from the Windows box to the DB2/iSeries using the ClientAccess "Data Transfer From iSeries" tool, with these settings:

IBM i name: 192.168.0.1
User: VCT130
Passwd: pass
File name: CHGDG#VL/AREA(AREA)

and it retrieves 23 records.

I'm trying to access the same data from a simple C# program summarised below:

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();

The conn and cmd objects get created OK, but the ExecuteReader() call fails with:

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

My line 27 is the call to cmd.ExecuteReader()

Any ideas please?


19 Nov Further thoughts:

[ Please excuse any clumsy etiquette, I'm a new poster here ]

  • Am I missing something? I'm thinking there are only 2 things to go
    wrong here:
    1. My code. No, too simple, and verified by @MikeWills' post
    2. My connection string
    3. Or could there be something else?


- re IBM.Data.DB2.iSeries.iDB2Command.verifyConnection()

Does someone here have access to the code to say what this method does, and what might be causing it to fail?

有帮助吗?

解决方案

Solved. I was missing the following:

  • need to add conn.Open() after conn= new ....
  • Add CheckConnectionOnOpen=true; to connection string
  • Remove / from query string

其他提示

See if this sample helps you out. I have written a library to make IBM server connections easier, this is a very old version of that library. I need to get the new version somewhere public again.

Update: My connection string is: DataSource=127.0.0.1;DefaultCollection=LIBRARY;Naming=sql;UserID=USER;Password=PASSWORD;

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top