0

I am trying to insert a PDF into a database as BLOB using the code below

  > [System.Reflection.Assembly]::LoadWithPartialName("System.Data.OracleClient")
    
    >
     $constr = "User Id=USER;Password=$password;Data Source=DB" 

Try { 
    >
     $filePath = 'C:\TEST PDF.pdf'  $Stream = Format-Hex -LiteralPath
    >
     $filePath   $queryString = "INSERT INTO TEST_TABLE (first_name, blob_data) VALUES (:one, :two)"  
   
    $connection = New-Object System.Data.OracleClient.OracleConnection($constr)  $connection.Open()
    
    $command = New-Object System.Data.OracleClient.OracleCommand($queryString, $connection)  
    
    $command.Parameters.Add("one", "SP_ERROR_ALERT") 
    $command.Parameters.Add("two", $Stream)  $command.ExecuteNonQuery() 
    $connection.Close() 
    }    Finally    {
    
            if ($connection -ne $null) 
            {
               $connection.Close()
               $connection.Dispose()
           }
     
            if ($command -ne $null) 
            {
               $command.Dispose()
            }   
    
    }

I have tried as many different ways I can think of but keep hitting an error complaining about the size of the BLOB. To test if would work I did an insert from another table containing Blobs and that worked fine - I therefore suspect my encoding.....

The error message I get is:

Exception calling "ExecuteNonQuery" with "0" argument(s): "Unknown datatype System.Object[] 
for parameter value of type Object."
3
  • 1
    What, exactly, is the error message you got? Edit it into the question, do not add it in a comment. Those are hard to read and ephemeral anyway. Commented May 23, 2022 at 20:39
  • Did you try Get-Content cmdlet with -AsByteStream? Commented May 23, 2022 at 21:32
  • You may also check this question whick is generally the same as in PS: Insert blob in oracle database with C# Commented May 23, 2022 at 21:34

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.