This web site uses Kentico CMS, the content management system for ASP.NET developers.

Community > Blogs > Max-PIT> IBM i5Series and PowerShell > December 2008 > PowerShell connecting to an i5 System using .NET
 

PowerShell connecting to an i5 System using .NET

Part 1 of 3

First, you need to install your "IBM iSeries Access for Windows" and make sure to include to load the ".NET provider".  Then, you can use the IBM ADO.NET provider to connect to the i5 System.

The i5 System is a very secure environment and may need to discuss access permissions to the database(s) with your i5 Securiy Officer. 

Now, the following simple sample will get you connected to the i5 System:

IBM ADO.NET connection

## Load GAC
[System.Reflection.Assembly]::LoadWithPartialName("System.Data")
[System.Reflection.Assembly]::LoadWithPartialName("IBM.Data.DB2.iSeries")

## Create strongly typed variables to hold your ID and Password
[string] $usr = 'YourUserID_here';
[string] $pwd = 'YourPassword_here';

## Build connection to i5
$i5Conn = New-Object System.Data.OleDb.OleDbConnection("Provider=IBMDA400;Data Source=IBMeServer;User ID=$usr;Password=$pwd;Initial Catalog=S1042B3A")
$i5Conn.Open();
 



Now, building a strongly typed variable served the purpose to hold the content as a full string.  I had the experience that my userID had a $ and by not defining my variable string enougn then PowerShell was expecting another variable.

Here's the one line provider string: (in the sample is wrapped at the end of the line)
"Provider=IBMDA400;Data Source=IBMeServer;User ID=$i5UID;Password=$i5PWD;Initial Catalog=S1042B3A"

Next, will use PowerShell to query an i5 table.

Posted: 12/6/2008 3:15:11 PM by Global Administrator | with 0 comments


Comments There are no comments on this post.

Title

Due to the fact that I have to also work with our IBM i5Series (aka AS/400), I needed to build a solution push data into the system.  So, using the "IBM iSeries Access for Windows" .NET provider, I was able to connect and use our DB2 databses in our i5 system.

It was hard for me to find information on How-to use the 'IBM iSeries Access to Windows" .NET provider to get my PowerShell script to work. I found one link (that I lost again) and a iSeries .NET presentation (C# code), help me complete these samples.

This blog section will provider with the necessary samples to:
1. Get connected to the i5 System
2. Do a SQL Query to a DB2 table
3. Executing a i5 Command

Please, make sure the your "security Office" provide you with the properly configured user ID and Password.


My favourite websites

Syndication

RSS

Post archive

This web site uses Kentico CMS, the content management system for ASP.NET developers.