Connecting to DB2 using PowerShell

眉间皱痕 提交于 2020-01-25 07:21:26

问题


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!


回答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!




回答2:


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.



来源:https://stackoverflow.com/questions/11862005/connecting-to-db2-using-powershell

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!