Automate IBM Informix Integration Tasks from PowerShell
The CData ADO.NET Provider for IBM Informix is a standard ADO.NET Provider that make it easy to accomplish data cleansing, normalization, backup, and other integration tasks by enabling real-time and bidirectional access to IBM Informix.
ADO.NET Provider
The ADO.NET Provider provides a SQL interface for IBM Informix; this tutorial shows how to use the Provider to create, retrieve, update, and delete IBM Informix data.
Once you have acquired the necessary connection properties, accessing IBM Informix data in PowerShell can be enabled in three steps.
Set the following properties to connect to IBM Informix
- Server: Set this to the name of the server running IBM Informix.
- Port: Set this to the port the IBM Informix server is listening on.
- Database: Set this to the name of the IBM Informix database.
- User: Set this to the username of a user allowed to access the database.
- Password: Set this to the password of a user allowed to access the database.
-
Load the provider's assembly:
[Reflection.Assembly]::LoadFile("C:\Program Files\CData\CData ADO.NET Provider for IBM Informix\lib\System.Data.CData.Informix.dll") -
Connect to IBM Informix:
$conn= New-Object System.Data.CData.Informix.InformixConnection("Server=10.0.1.2;Port=50000;User=admin;Password=admin;Database=test;") $conn.Open() -
Instantiate the InformixDataAdapter, execute an SQL query, and output the results:
$sql="SELECT Id, Price from Books" $da= New-Object System.Data.CData.Informix.InformixDataAdapter($sql, $conn) $dt= New-Object System.Data.DataTable $da.Fill($dt) $dt.Rows | foreach { Write-Host $_.id $_.price }
Update IBM Informix Data
$cmd = New-Object System.Data.CData.Informix.InformixCommand("UPDATE Books SET Category='US' WHERE Id = @myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.Informix.InformixParameter("@myId","10456255-0015501366")))
$cmd.ExecuteNonQuery()
Insert IBM Informix Data
$cmd = New-Object System.Data.CData.Informix.InformixCommand("INSERT INTO Books (Category) VALUES (@myCategory)", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.Informix.InformixParameter("@myCategory","US")))
$cmd.ExecuteNonQuery()
Delete IBM Informix Data
$cmd = New-Object System.Data.CData.Informix.InformixCommand("DELETE FROM Books WHERE Id=@myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.Informix.InformixParameter("@myId","001d000000YBRseAAH")))
$cmd.ExecuteNonQuery()
CodeProject