Jim, I think you got it! The innerexception didn't have what I needed, but the below command did!
$error[6].exception.GetBaseException() An attempt was made to load an assembly from a network location which would have caused the assembly to be sandboxed in previous versions of the .NET Framework. This release of the .NET Framework does not enable CAS policy by default, so this load may be dangerous. If this load is not intended to sandbox the assembly, please enable the loadFromRemoteSources switch. See http://go.microsoft.com/fwlink/?LinkId=155569 for more information. It looks like I just have to enable LoadFromRemoteSources in the CAS policy for .NET 4.0. Basically creating a .config file in the root of the PowerShell directory. http://techstumbler.blogspot.com/2012/01/loading-remote-assemblies-in-powershell.html Unfortunately I have tried this, but still get the same dang error. I have verified the following: [environment]::version.toscript() gives me 4.0.30319.296 I have tried all variations of the version for .NET 4.0: v4.0, v4.0.30319, v4.0.30319.296 and closed and reopened the shell each time. Any more ideas? I feel so close!! Daniel Ratliff From: [email protected] [mailto:[email protected]] On Behalf Of Jim Truher Sent: Thursday, August 15, 2013 8:33 PM To: [email protected] Subject: RE: [powershell] RE: Anyone ever use MySQL connector? Why is .NET 4.5 a requirement?! Aha! That's quite a bit different, it's likely one of the dependent assemblies - do you know the list dependent assemblies? sometimes $error[0].exception.innerexception has more info jim From: [email protected]<mailto:[email protected]> [mailto:[email protected]]<mailto:[mailto:[email protected]]> On Behalf Of Daniel Ratliff Sent: Thursday, August 15, 2013 5:22 PM To: [email protected]<mailto:[email protected]> Subject: RE: [powershell] RE: Anyone ever use MySQL connector? Why is .NET 4.5 a requirement?! Sorry, I didn't mention further up in the script I am doing something similar. [environment]::CurrentDirectory = Get-Location -PSProvider FileSystem write-host "Changing directory to:"([environment]::currentdirectory) -ForegroundColor Yellow I tried $pwd and $psscriptroot and still got the same error. Below is the exact error. Line 75 is the add-type line. 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 Daniel Ratliff From: [email protected]<mailto:[email protected]> [mailto:[email protected]] On Behalf Of Michael B. Smith Sent: Thursday, August 15, 2013 3:05 PM To: [email protected]<mailto:[email protected]> Subject: RE: [powershell] RE: Anyone ever use MySQL connector? Why is .NET 4.5 a requirement?! This is generally what I would use in that scenario (ps2 and ps3 compatible): $dllPath = ( Join-Path ( Split-Path $MyInvocation.MyCommand.Path -Parent) MySql.Data.dll ) # [void][System.Reflection.Assembly]::LoadFrom( $dllPath ) add-type -Path $dllPath From: [email protected]<mailto:[email protected]> [mailto:[email protected]]<mailto:[mailto:[email protected]]> On Behalf Of Trevor Sullivan Sent: Thursday, August 15, 2013 2:55 PM To: [email protected]<mailto:[email protected]> Subject: RE: [powershell] RE: Anyone ever use MySQL connector? Why is .NET 4.5 a requirement?! $PWD gets the "current directory." There is a big difference between $PSScriptRoot and $PWD. Typically, you will want to use $PSScriptRoot. See: Get-Help about_Automatic_Variables Cheers, Trevor Sullivan [WordPress Logo 32px]<http://trevorsullivan.net/> [Twitter Logo 32px] <http://twitter.com/pcgeek86> [Facebook Logo 32px] <http://facebook.com/trevor.sullivan> [Google+ Icon 32px] <https://plus.google.com/106658223083457664096> From: [email protected]<mailto:[email protected]> [mailto:[email protected]] On Behalf Of Jim Truher Sent: Thursday, August 15, 2013 1:36 PM To: [email protected]<mailto:[email protected]> Subject: [powershell] RE: Anyone ever use MySQL connector? Why is .NET 4.5 a requirement?! Try using "$PWD/MySql.Data.dll" instead From: [email protected]<mailto:[email protected]> [mailto:[email protected]] On Behalf Of Daniel Ratliff Sent: Thursday, August 15, 2013 10:01 AM To: [email protected]<mailto:[email protected]> Subject: [powershell] Anyone ever use MySQL connector? Why is .NET 4.5 a requirement?! I am writing a script to connect out to a MySQL db. I downloaded the latest Connector and extracted MySQL.Data.dll. I was testing on my Win7 x64 box (PoSH 3.0 and .NET 4.5) and I can load the assembly just fine, but any Win7 machine with .NET 4.0 will not load it! I have tried the v2.0, v4.0, and v.4.5 dll to no avail. I also tried using the add-type command as well. The error I get is object cannot be loaded 0x80131515. Anything online I search for says I have the wrong path, but I doubt that is the case because if I install .NET 4.5 the script works without modification! Any ideas? 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 } Daniel Ratliff The information transmitted is intended only for the person or entity to which it is addressed and may contain CONFIDENTIAL material. If you receive this material/information in error, please contact the sender and delete or destroy the material/information. ================================================ Did you know you can also post and find answers on PowerShell in the forums? http://www.myitforum.com/forums/default.asp?catApp=1 ================================================ Did you know you can also post and find answers on PowerShell in the forums? http://www.myitforum.com/forums/default.asp?catApp=1 ================================================ Did you know you can also post and find answers on PowerShell in the forums? http://www.myitforum.com/forums/default.asp?catApp=1 ================================================ Did you know you can also post and find answers on PowerShell in the forums? http://www.myitforum.com/forums/default.asp?catApp=1 The information transmitted is intended only for the person or entity to which it is addressed and may contain CONFIDENTIAL material. If you receive this material/information in error, please contact the sender and delete or destroy the material/information. ================================================ Did you know you can also post and find answers on PowerShell in the forums? http://www.myitforum.com/forums/default.asp?catApp=1 ================================================ Did you know you can also post and find answers on PowerShell in the forums? http://www.myitforum.com/forums/default.asp?catApp=1 The information transmitted is intended only for the person or entity to which it is addressed and may contain CONFIDENTIAL material. If you receive this material/information in error, please contact the sender and delete or destroy the material/information. ================================================ Did you know you can also post and find answers on PowerShell in the forums? http://www.myitforum.com/forums/default.asp?catApp=1
<<inline: image001.gif>>
<<inline: image002.gif>>
<<inline: image003.gif>>
<<inline: image004.gif>>
