DB2和Powershell与DataSet?

时间:2011-06-21 10:23:42

标签: powershell db2

我正在尝试查询DB2 9.7 Express附带的SAMPLE数据库,虽然脚本工作并显示输出,但我在$da.Fill($ds)语句中收到错误。

任何人都可以提供有关正在发生的事情的任何见解吗?

$cn = new-object system.data.OleDb.OleDbConnection("Provider=DB2OLEDB;User ID=geekadmin;Password=geekadmin;Initial Catalog=SAMPLE;Network Transport Library=TCP;Host CCSID=37;PC Code Page=1252;Network Address=192.168.1.205;Network Port=50000;Package Collection=<collection>;Default Schema=<schema>;Process Binary as Character=False;Units of Work=RUW;DBMS Platform=DB2/NT;Defer Prepare=False;Persist Security Info=True;Connection Pooling=False;");

$ds = new-object "System.Data.DataSet" "dsEmployee5" 

$q = "SELECT EMPNO"
$q = $q + ",FIRSTNME"
$q = $q + ",LASTNAME"
$q = $q + " FROM DMOHORN.EMPLOYEE" 

$q

$da = new-object "System.Data.OleDb.OleDbDataAdapter" ($q, $cn) 

$da.Fill($ds)


$dtPerson = new-object "System.Data.DataTable" "dtEmployee5" 

$dtPerson = $ds.Tables[0] 

$dtPerson | FOREACH-OBJECT { " " + $_.EMPNO + ": " + $_.FIRSTNME + ", " + $_.LASTNAME }

SELECT EMPNO,FIRSTNME,LASTNAME FROM GeekAdmin.EMPLOYEE
Exception calling "Fill" with "1" argument(s): "The cursor specified in a FETCH statement or CLOSE statement is not open or a cursor variable in a cursor scalar function reference is not open. SQLSTATE: 24501, SQLCO
DE: -501"
At line:13 char:9
+ $da.Fill <<<< ($ds)
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException


 000010: CHRISTINE, HAAS

 000020: MICHAEL, THOMPSON

 000030: SALLY, KWAN

 000050: JOHN, GEYER

 000060: IRVING, STERN

 000070: EVA, PULASKI

 000090: EILEEN, HENDERSON

 000100: THEODORE, SPENSER

 000110: VINCENZO, LUCCHESSI

 000120: SEAN, O'CONNELL

 000130: DELORES, QUINTANA

 000140: HEATHER, NICHOLLS

 000150: BRUCE, ADAMSON

 000160: ELIZABETH, PIANKA

 000170: MASATOSHI, YOSHIMURA

 000180: MARILYN, SCOUTTEN

 000190: JAMES, WALKER

 000200: DAVID, BROWN

 000210: WILLIAM, JONES

 000220: JENNIFER, LUTZ

 000230: JAMES, JEFFERSON

 000240: SALVATORE, MARINO

 000250: DANIEL, SMITH

 000260: SYBIL, JOHNSON

 000270: MARIA, PEREZ

 000280: ETHEL, SCHNEIDER

 000290: JOHN, PARKER

 000300: PHILIP, SMITH

 000310: MAUDE, SETRIGHT

 000320: RAMLAL, MEHTA

 000330: WING, LEE

 000340: JASON, GOUNOT

 200010: DIAN, HEMMINGER

 200120: GREG, ORLANDO

 200140: KIM, NATZ

 200170: KIYOSHI, YAMAMOTO

 200220: REBA, JOHN

 200240: ROBERT, MONTEVERDE

 200280: EILEEN, SCHWARTZ

 200310: MICHELLE, SPRINGER

 200330: HELENA, WONG

 200340: ROY, ALONZO

1 个答案:

答案 0 :(得分:0)

我最终使用其他提供商解决了这个问题。

此处发布的示例和解决方案。

http://myblog4fun.com/archive/2012/01/14/using-powershell-to-access-db2.aspx