I was absent for last four months or more from the blogging world. Blame our Oracle EBS 12.2.10 to 12.2.14 upgrade for that. As, Developers like you and me are facing the “imminent” danger of being wiped out by the AI dudes, I wanted to catch up with them before it was too late, in addition to fixing the upgrade mess.
For such a Project, I made a small Powershell script, that generated JSON files against few of existing views. AI generated the Powershell script. I modified the connection strings & executed the script using “Windows PowerShell”. All good and was impressed by the clean code blocks generated by Copilot.
As I often work with Linux servers, had the latest PowerShell pinned to my taskbar & couple of days back, wanted to make some changes to my toy project. Made them, opened up the PowerShell 7.6.3 shell and tried to execute the script and was slapped with the error:
MethodInvocationException: Exception calling "Open" with "0" argument(s): "Connection request timed out"
Then my AI dude (Copilot) churned out few TONs of suggestions until I gave up hurting my fingers further. Moved to Google Gemini & as usual, gave me hope and I ended up with another N number of experiments.
Throughout my development career, blessings came in the shape of blog posts, accidental findings… & this time was no different. After losing hopes on both the AI assistants, for some unknown reasons, I opened up “Windows PowerShell” and tried to execute the same script that was working previously and was not working on PowerShell 7.6.3!
Now, I have something to work on. Gemini explained me about the differences between the Oracle’s Managed Data Access dll and the 7.6.3 .Net Core architecture. I copied the Managed Data Access Core dll from one of my recent .Net Core Web API projects (Don’t get confused because both DLL files “look” the same), modified the PowerShell script to check its’ own version before continuing with the script. Now, my script works from both Windows PowerShell and PowerShell 7+ environments.
Fixed PowerShell script, enjoy :)
# Load Oracle Managed Data Access assembly# Get the current running PowerShell version$psVersion = $PSVersionTable.PSVersion# Define the target comparison version (7.6.3)$targetVersion = [version]"7.6.3"if ($psVersion -ge $targetVersion) { Write-Host "PowerShell version is $psVersion (7.6.3 or above). Loading local DLL..." -ForegroundColor Green Add-Type -Path "C:\Scripts\Oracle.ManagedDataAccess.dll"}else { Write-Host "PowerShell version is $psVersion (Below 7.6.3). Loading Oracle Home DLL..." -ForegroundColor Yellow Add-Type -Path "D:\Oracle\product\19.3.0\dbhome_1\ODP.NET\managed\common\Oracle.ManagedDataAccess.dll"}$oracleConnectionString = "User Id=apps;Password=apps;Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.1.10)(PORT=1526))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=TEST)));Connection Timeout=60;"# SQL query to select all columns from the view$sqlQuery = "SELECT ORGANIZATION_ID, ORGANIZATION_CODE, ORGANIZATION_NAME FROM APPS.ORG_ORGANIZATION_DEFINITIONS"# Output JSON file path$outputFile = "C:\Scripts\logs\ORG_LIST.json"# Initialize connection object$connection = New-Object Oracle.ManagedDataAccess.Client.OracleConnection($oracleConnectionString)try { # Attempt to open connection $connection.Open() Write-Output "Connected to Oracle database successfully." # Create command $command = $connection.CreateCommand() $command.CommandText = $sqlQuery # Execute query $reader = $command.ExecuteReader() $rows = @() while ($reader.Read()) { $row = @{} for ($i = 0; $i -lt $reader.FieldCount; $i++) { $row[$reader.GetName($i)] = $reader.GetValue($i) } $rows += [PSCustomObject]$row } # Close reader $reader.Close() # Convert to JSON and save try { $rows | ConvertTo-Json -Depth 3 | Set-Content -Path $OutputFile -Encoding utf8 Write-Output "Export complete. JSON saved to $outputFile" } catch { Write-Error "Failed to convert data to JSON or write to file: $_" }}catch [Oracle.ManagedDataAccess.Client.OracleException] { Write-Error "Oracle connection or query error: $($_.Exception.Message)"}catch { Write-Error "Unexpected error occurred: $($_.Exception.Message)"}finally { if ($connection.State -eq 'Open') { $connection.Close() Write-Output "Oracle connection closed." }}














