Using Microsoft.Data.SqlClient in PowerShell

1.2k Views Asked by At

I would like to use the Microsoft.Data.SqlClient namespace/ objects in a PowerShell script. Two (click1, click2) Github posts provide a way to load the correct dll's, but the solutions don't seem to work anymore.

E.g. result of the first solution while copying the next files:

(Packages copied from .nuget/packages folder)

  • Microsoft.Data.SqlClient.dll
  • Microsoft.Data.SqlClient.SNI.x64.dll
  • Microsoft.Identity.Client.dll

Result: Could not load file or assembly 'System.Runtime, Version=6.0.0.0'

In addition, I've tried to create a Dummy Console App -> Added the Microsoft.Data.SqlClient Nuget package -> built the project and copied all dll's to the same folder as the PS script. As soon as I start the script (using the 'Add-Type -Path' construction), it results in errors, such as 'couldn't load file or assembly - wrong version...' (this is strange, because the folder contains all dll's...)

Could you provide an alternative solution/ steps in order to use the described package in a PS script?

0

There are 0 best solutions below