Connecting to DB2 using PowerShell

0

I'm trying to connect to a DB2 database and execute some queries. I had it working a few days ago, but now it's giving some really strange errors and I can't figure out why.

The PowerShell connection code

$connection = New-Object System.Data.OleDb.OleDbConnection("Provider=IBMDADB2;Database=X;HostName=X;Protocol=TCPIP;Port=X;Uid=X;Pwd=X;CurrentSchema=X");
$ds = New-Object "System.Data.DataSet"  

$da = New-Object System.Data.OleDb.OleDbDataAdapter($QuerySQL, $connection)
$da.Fill($ds)

$ds.Tables[0].Rows |
    select * -ExcludeProperty RowError, RowState, HasErrors, Name, Table, ItemArray |
    Export-Csv "c:\Scripts\results.csv" -encoding "unicode" -notype

The error I'm seeing:

Exception calling "Fill" with "1" argument(s): "No error message available, result code: E_UNEXPECTED(0x8000FFFF)."

Anybody got any ideas why this is cropping up?

I've got other scripts that use Fill() in the exact same way an don't produce errors, so this is really baffling me!

powershell
db2
asked on Stack Overflow Aug 8, 2012 by YYZ • edited Jun 3, 2019 by Ansgar Wiechers

2 Answers

1

Ok, I've figured it out.

You need to run powershell as admin to use the DB2 driver. Why this is, I don't know, but that's how I fixed it!

answered on Stack Overflow Aug 8, 2012 by YYZ
0

You need to add the user to the DB2Users or DB2Admns groups. The local Administrators group works, too, but for security reasons the other two groups are more appropriate. These groups are typically created by default on the server to which you install DB2. They are local groups.


User contributions licensed under CC BY-SA 3.0