Automate SAP HANA Integration Tasks from PowerShell
The CData ADO.NET Provider for SAP HANA 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 SAP HANA.
ADO.NET Provider
The ADO.NET Provider provides a SQL interface for SAP HANA; this tutorial shows how to use the Provider to create, retrieve, update, and delete SAP HANA data.
Once you have acquired the necessary connection properties, accessing SAP HANA data in PowerShell can be enabled in three steps.
Set the Server, Database and Port properties to specify the address of your SAP Hana database to interact with. Set the User and the Password properties to authenticate to the server.
-
Load the provider's assembly:
[Reflection.Assembly]::LoadFile("C:\Program Files\CData\CData ADO.NET Provider for SAP HANA\lib\System.Data.CData.SAPHANA.dll") -
Connect to SAP HANA:
$conn= New-Object System.Data.CData.SAPHANA.SAPHANAConnection("User=system;Password=mypassword;Server=localhost;Database=systemdb;") $conn.Open() -
Instantiate the SAPHANADataAdapter, execute an SQL query, and output the results:
$sql="SELECT Name, OwnerId from Buckets" $da= New-Object System.Data.CData.SAPHANA.SAPHANADataAdapter($sql, $conn) $dt= New-Object System.Data.DataTable $da.Fill($dt) $dt.Rows | foreach { Write-Host $_.name $_.ownerid }
Update SAP HANA Data
$cmd = New-Object System.Data.CData.SAPHANA.SAPHANACommand("UPDATE Buckets SET Name='TestBucket' WHERE Id = @myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.SAPHANA.SAPHANAParameter("@myId","10456255-0015501366")))
$cmd.ExecuteNonQuery()
Insert SAP HANA Data
$cmd = New-Object System.Data.CData.SAPHANA.SAPHANACommand("INSERT INTO Buckets (Name) VALUES (@myName)", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.SAPHANA.SAPHANAParameter("@myName","TestBucket")))
$cmd.ExecuteNonQuery()
Delete SAP HANA Data
$cmd = New-Object System.Data.CData.SAPHANA.SAPHANACommand("DELETE FROM Buckets WHERE Id=@myId", $conn)
$cmd.Parameters.Add((New-Object System.Data.CData.SAPHANA.SAPHANAParameter("@myId","001d000000YBRseAAH")))
$cmd.ExecuteNonQuery()
CodeProject