Hello,
I have written a PowerShell script to connect to a MySQL database to query for some information. I am using the extracted MySQL.data.dll and the script works fine, if .NET Framework 4.5 is installed. If the machine only has .NET Framework 4.0 installed, I get the below error.
add-type : Could not load file or assembly 'file:///P:\MySql.Data.dll' or
one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)
At P:\printer.ps1:75 char:5
+ add-type -Path "$PWD/MySql.Data.dll"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Add-Type], FileLoadException
+ FullyQualifiedErrorId : System.IO.FileLoadException,Microsoft.PowerShell.Commands.AddTypeCommand
The target environment is Win7 x64. I have been searching online for the last few days and found no reference that .NET Framework 4.5 was required. I am using PowerShell 3.0 but I would have thought one of the other .dlls would have worked. I have tried using the v2.0, v4.0, and v4.5 dlls to no avail. See below for the entire script.
[environment]::CurrentDirectory = Get-Location -PSProvider FileSystem
write-host "Changing directory to:"([environment]::currentdirectory) -ForegroundColor Yellow
function global:PrinterList {
Param(
[string]$printerip
)
$mysqlserver = "server"
$mysqldb = "db"
$mysqluser = "user"
$mysqlpassword = 'pass'
$mysqlconnectionstring = "Server=$mysqlserver; Database=$mysqldb; User=$mysqluser; Password=$mysqlpassword"
$mysqlquery = "
SELECT Model,IP,Building,Floor,Printer_ID
FROM printers
WHERE ip = '$printerip'"
#[void][System.Reflection.Assembly]::LoadFrom(".\MySql.Data.dll")
add-type -Path ".\MySql.Data.dll"
$connection = New-Object MySql.Data.MySqlClient.MySqlConnection
$connection.ConnectionString = $mysqlconnectionString
$connection.Open()
$command = New-Object MySql.Data.MySqlClient.MySqlCommand($mysqlquery, $connection)
$dataAdapter = New-Object MySql.Data.MySqlClient.MySqlDataAdapter($command)
$global:mysqltable = New-Object System.Data.DataTable
$recordCount = $dataAdapter.Fill($mysqltable)
$global:mysqltable
}
Any ideas? Is installing .NET Framework 4.5 my only option?
I have written a PowerShell script to connect to a MySQL database to query for some information. I am using the extracted MySQL.data.dll and the script works fine, if .NET Framework 4.5 is installed. If the machine only has .NET Framework 4.0 installed, I get the below error.
add-type : Could not load file or assembly 'file:///P:\MySql.Data.dll' or
one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)
At P:\printer.ps1:75 char:5
+ add-type -Path "$PWD/MySql.Data.dll"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Add-Type], FileLoadException
+ FullyQualifiedErrorId : System.IO.FileLoadException,Microsoft.PowerShell.Commands.AddTypeCommand
The target environment is Win7 x64. I have been searching online for the last few days and found no reference that .NET Framework 4.5 was required. I am using PowerShell 3.0 but I would have thought one of the other .dlls would have worked. I have tried using the v2.0, v4.0, and v4.5 dlls to no avail. See below for the entire script.
[environment]::CurrentDirectory = Get-Location -PSProvider FileSystem
write-host "Changing directory to:"([environment]::currentdirectory) -ForegroundColor Yellow
function global:PrinterList {
Param(
[string]$printerip
)
$mysqlserver = "server"
$mysqldb = "db"
$mysqluser = "user"
$mysqlpassword = 'pass'
$mysqlconnectionstring = "Server=$mysqlserver; Database=$mysqldb; User=$mysqluser; Password=$mysqlpassword"
$mysqlquery = "
SELECT Model,IP,Building,Floor,Printer_ID
FROM printers
WHERE ip = '$printerip'"
#[void][System.Reflection.Assembly]::LoadFrom(".\MySql.Data.dll")
add-type -Path ".\MySql.Data.dll"
$connection = New-Object MySql.Data.MySqlClient.MySqlConnection
$connection.ConnectionString = $mysqlconnectionString
$connection.Open()
$command = New-Object MySql.Data.MySqlClient.MySqlCommand($mysqlquery, $connection)
$dataAdapter = New-Object MySql.Data.MySqlClient.MySqlDataAdapter($command)
$global:mysqltable = New-Object System.Data.DataTable
$recordCount = $dataAdapter.Fill($mysqltable)
$global:mysqltable
}
Any ideas? Is installing .NET Framework 4.5 my only option?