Repository navigation
"Microsoft.Data. SqlClient is not supported on this platform." when trying to use it in PowerShell 7.0.2 #623
Description
Activity
try use
\Microsoft.Data.SqlClient.2.0.0\runtimes\win\lib\netcoreapp2.1\Microsoft.Data.SqlClient.dllistead of\Microsoft.Data.SqlClient.2.0.0\lib\netcoreapp2.1\Microsoft.Data.SqlClient.dll"Reacted by Jan Nitecki and mathobbsReacted by Masayuki OzawaThank you.
I used a DLL under the win directory and it worked!I was able to load the assembly, but when I tried to open it, I got the following error As a result, we were unable to open a connection.
$dllPath = Join-Path $ENV:USERPROFILE "AppData\Local\PackageManagement\NuGet\Packages\Microsoft.Data.SqlClient.2.0.0\runtimes\win\lib\netcoreapp2.1\Microsoft.Data.SqlClient.dll" Add-Type -Path $dllPath $con = New-Object Microsoft.Data.SqlClient.SqlConnection $con.ConnectionString = "Server=xxxx;user=xxxxx;password=xxxxx" $con.Open() $con.State $con.Close() MethodInvocationException: Line | 6 | $con.Open() | ~~~~~~~~~~~ | Exception calling "Open" with "0" argument(s): "The type initializer for 'Microsoft.Data.SqlClient.TdsParser' threw an exception."Up to 1.0.19269.1 I was able to open a connection with such code, but since 2.0, the assembly required has changed?
having same, try 1.1.3 , tested from my side and works
@MartinHBA Thank you for Reply.
It worked on 1.1.3 in my environment as well.Using 2.0.0-preview4.20142.4 or later, I got the error "The type initializer for 'Microsoft.Data.SqlClient.TdsParser' threw an exception."
(No exception occurred until 2.0.0-preview3.20122.2.)it's the Powershell, I am afraid it's not possible to load assembly with all dependencies automatically. During installation of package it's all downloaded, but Add-Type doesn't support loading assembly including all dependent assemblies. Just one single DLL, all others that might be required are missing. For example if you try windows auth it fails with required SNI. I think this is broader issue with PS loading needed assemblies, at the moment I see only loading it one by one and it doesn't work well. If you will be able to load assembly with all dependent automatically, let me know :)
As far as I know this will be addressed in PSGet v3.Reacted by Masayuki Ozawa and Cheena MalhotraAdded Microsoft.Data.SqlClient.SNI.runtime from "2.0.0-preview4.20142.4" to the dependency.
I have placed Microsoft.Data.SqlClient.dll in the same directory as Microsoft.Data.SqlClient.dll and it works :)The error occurred because you did not check for dependencies on the latest version.
Thank you for your advice!!
Thanks to you, I was able to make it work.Reacted by MartinHBA- addedExternal 🔗Issue is in an external componentIssue is in an external component
on Jun 22, 2020 If you're installing all dependencies by yourself, please make sure you install all latest versions of required dependencies as well, as referenced by Microsoft.Data.SqlClient.
Reacted by Masayuki Ozawa
The following environments are used as PowerShell Core.
Download 2.0.0.
Now, the following script will run Exception calling ".ctor" with "0" argument(s): "Microsoft.Data. SqlClient is not supported on this platform. It occurs.
Can't I run Microsoft.Data. SqlClient 2.0.0 on PowerShell Core 7.0.2?