-
Notifications
You must be signed in to change notification settings - Fork 300
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Not able to get Microsoft.Data.SqlClient working on Powershell under Linux #1301
Comments
There are two problems that usually occur with powershell usage. 1) failure to restore the dependencies, 2) attempt to use the ref assembly. This sounds like 1 to me, the .cctor for that type uses the System.Configuration system and if you haven't restored that dependency it won't be able to find it and will fail. Check the dependencies on nuget.org and see if adding the ones relevant to your system helps. |
Hi @rajivml Have you tried specifying |
@cheenamalhotra Hi, which library are you referring to System.Data.SqlClient or Microsoft.Data.SqlClient with Microsoft.Data.SqlClient library, we are not even able to set connectionString property on connection object, if we see the Write-Verbose output, the connection string is empty, that's why con.Open() is throwing the below error Is there a working example anywhere in the Official Microsoft documentation which we can refer to to get it working ? Am looking for a linux specific example, found some github issues but they are all windows related
|
@rajivml I have spent sometime and I figured out the issue. Keep in mind that we, developers of SqlClient, are not PowerShell experts/developers. The issue seems to come from the fact that PowerShell is not handling Nugets packages easily, look at PowerShell/PowerShell#6724 try{
$conn.Open()
}catch{
$_.Exception
} Microsoft.Identity.Client Version 4.22.0 needs to be loaded. Remember [System.AppDomain]::CurrentDomain.GetAssemblies() and you will get a list of loaded libraries. |
@rajivml let me know if the problem has been solved. Thanks |
HI @JRahnama , Thank you very much for looking into it, looks like some of the dependent dll's are not compiled for linux :( |
Linux builds use the native SNI implementation and the nuget restore process understands that and provides the correct dlls, those native sni dlls aren't needed and the fact that you're trying to use them is a problem. |
Thanks a lot guys @Wraith2 @JRahnama and @cheenamalhotra. This worked, you can resolve the ticket
|
Docs update/addition? |
Possible but that would make it look like a supported scenario where as far as I know it isn't, it can be made to work but any change to dependencies could break it and that's on the user to fix. |
Right - more like a community blog post then, I guess |
HI,
Right now we are using System.Data.SqlClient to validate sql connection strings via powershell but we realized this library doesn't support this additional connection param i.e. Column Encryption Setting=enabled
with this we are always running into ,

We even tried "SqlServer" library, but the error message is still the same
On debugging why it's the case, we found this article which state Microsoft.Data.SqlClient is the way to go,
https://devblogs.microsoft.com/dotnet/introducing-the-new-microsoftdatasqlclient/
Now problem with Microsoft.Data.SqlClient is , from last 2 days two of us are trying to figure out how to even get this library working on powershell running inside a RHEL container
We installed library like this,
and then we are trying to validate connection string like this and irrespective of whatever DLL path we pass, we are always running into the same error i.e,
MethodInvocationException: Exception calling "Open" with "0" argument(s): "The type initializer for 'Microsoft.Data.SqlClient.SqlAuthenticationProviderManager' threw an exception."
Can you please help us understand how do we fix this or share us an working example which is powershell and linux based
we tried all this already and nothing works,
#623
https://gist.github.com/MartinHBA/86c6014175758a07b09fa7bb76ba8e27
The text was updated successfully, but these errors were encountered: