Skip to content

Instantly share code, notes, and snippets.

@MartinHBA
Last active June 27, 2024 17:56
Show Gist options
  • Save MartinHBA/86c6014175758a07b09fa7bb76ba8e27 to your computer and use it in GitHub Desktop.
Save MartinHBA/86c6014175758a07b09fa7bb76ba8e27 to your computer and use it in GitHub Desktop.
Microsoft.Data.SqlClient with PowerShell

Microsoft.Data.SqlClient with PowerShell

This is step by step guide how to use new .NET namespace Microsoft.Data.SqlClient with Powershell. I've tested connection string using SQL login and Windows login. This could not fit you all but might provide you some ideas.

Scenario

Fresh Windows Server 2016 in my case Azure VM.

  1. Install .NET CORE 3.0 SDK it must be SDK

  2. Install PowerShell 7 Core with command as admin

    dotnet tool install --global PowerShell
  3. Run

    pwsh
  4. Check that your PowerShell Core is with NuGet package provider

    Get-PackageProvider
  5. Install package

    Install-Package Microsoft.Data.SqlClient
  6. Copy dependent DLL (Microsoft.Data.SqlClient.SNI.dll - correct runtime, in my case x64) to folder with your main DLL

  7. Run your PowerShell script with PowerShell Core

PowerShell script

Microsoft.Data.SqlClient.dll location

Since I was installing .NET CORE as first step and having PowerShell Core as well. Obviously I am adding dll located in Runtimes and netcoreapp2.1 subfolder. In my case

C:\Program Files\PackageManagement\NuGet\Packages\Microsoft.Data.SqlClient.2.0.0\runtimes\win\lib\netcoreapp2.1\Microsoft.Data.SqlClient.dll

Adding dependent assembly SNI

Example script body

Add-Type -AssemblyName System.Data
Add-Type -Path ('C:\Program Files\PackageManagement\NuGet\Packages\Microsoft.Data.SqlClient.2.0.0\runtimes\win\lib\netcoreapp2.1\Microsoft.Data.SqlClient.dll') -ReferencedAssemblies Microsoft.Data.SqlClient.SNI

## building connection
    $conn = new-object Microsoft.Data.SqlClient.SqlConnection
    $conn.connectionstring = 'SERVER=VMtestPWSH;DATABASE=TestDB;user=mylogin;password=SuperHardPWD'
    Write-Verbose $conn.connectionstring
    $conn.open()
## running sample query
    $query = "select * from sys.sysfiles"
    $cmd = New-object Microsoft.Data.SqlClient.SqlCommand($query,$conn)
    $ds = New-Object system.Data.DataSet
       (New-Object Microsoft.Data.SqlClient.SqlDataAdapter($cmd)).fill($ds) | out-null
## returining query result
    $ds.Tables[0]
## closing connection
    $conn.Close()

Microsoft.Data.SqlClient with .NET Core project

In this 2 simple steps below you can see how easy and fully integrated it is when you try to use nuget package with .NET project compared to PowerShell script above

PS C:\proj> dotnet new 'Console Application'
Getting ready...
The template "Console Application" was created successfully.

Processing post-creation actions...
Running 'dotnet restore' on C:\proj\proj.csproj...
  Restore completed in 95.14 ms for C:\proj\proj.csproj.

Restore succeeded.
PS C:\proj> dotnet add package Microsoft.Data.SqlClient
  Writing C:\Users\martin1\AppData\Local\Temp\2\tmpD964.tmp
info : Adding PackageReference for package 'Microsoft.Data.SqlClient' into project 'C:\proj\proj.csproj'.
info : Restoring packages for C:\proj\proj.csproj...
info :   GET https://www.nuget.org/api/v2/FindPackagesById()?id='Microsoft.Data.SqlClient'&semVerLevel=2.0.0
info :   OK https://www.nuget.org/api/v2/FindPackagesById()?id='Microsoft.Data.SqlClient'&semVerLevel=2.0.0 818ms
info :   GET https://www.nuget.org/api/v2/package/Microsoft.Data.SqlClient/1.0.19269.1
info :   OK https://www.nuget.org/api/v2/package/Microsoft.Data.SqlClient/1.0.19269.1 988ms
info :   GET https://www.nuget.org/api/v2/FindPackagesById()?id='Microsoft.Win32.Registry'&semVerLevel=2.0.0
info :   GET https://www.nuget.org/api/v2/FindPackagesById()?id='runtime.native.System.Data.SqlClient.sni'&semVerLevel=2.0.0
info :   GET https://www.nuget.org/api/v2/FindPackagesById()?id='System.Security.Principal.Windows'&semVerLevel=2.0.0
info :   GET https://www.nuget.org/api/v2/FindPackagesById()?id='System.Text.Encoding.CodePages'&semVerLevel=2.0.0
info :   GET https://www.nuget.org/api/v2/FindPackagesById()?id='System.Configuration.ConfigurationManager'&semVerLevel=2.0.0
info :   GET https://www.nuget.org/api/v2/FindPackagesById()?id='System.Runtime.Caching'&semVerLevel=2.0.0
info :   GET https://www.nuget.org/api/v2/FindPackagesById()?id='Microsoft.Identity.Client'&semVerLevel=2.0.0
info :   OK https://www.nuget.org/api/v2/FindPackagesById()?id='Microsoft.Win32.Registry'&semVerLevel=2.0.0 148ms
info :   GET https://www.nuget.org/api/v2/package/Microsoft.Win32.Registry/4.5.0
info :   OK https://www.nuget.org/api/v2/package/Microsoft.Win32.Registry/4.5.0 135ms
info :   OK https://www.nuget.org/api/v2/FindPackagesById()?id='runtime.native.System.Data.SqlClient.sni'&semVerLevel=2.0.0 433ms
info :   GET https://www.nuget.org/api/v2/FindPackagesById()?id='System.Security.AccessControl'&semVerLevel=2.0.0
info :   OK https://www.nuget.org/api/v2/FindPackagesById()?id='System.Text.Encoding.CodePages'&semVerLevel=2.0.0 455ms
info :   GET https://www.nuget.org/api/v2/package/runtime.native.System.Data.SqlClient.sni/4.4.0
info :   OK https://www.nuget.org/api/v2/FindPackagesById()?id='Microsoft.Identity.Client'&semVerLevel=2.0.0 541ms
info :   GET https://www.nuget.org/api/v2/package/System.Text.Encoding.CodePages/4.5.0
info :   OK https://www.nuget.org/api/v2/FindPackagesById()?id='System.Security.AccessControl'&semVerLevel=2.0.0 174ms
info :   GET https://www.nuget.org/api/v2/package/Microsoft.Identity.Client/3.0.8
info :   OK https://www.nuget.org/api/v2/package/runtime.native.System.Data.SqlClient.sni/4.4.0 122ms
info :   GET https://www.nuget.org/api/v2/FindPackagesById()?id='runtime.win-arm64.runtime.native.System.Data.SqlClient.sni'&semVerLevel=2.0.0
info :   GET https://www.nuget.org/api/v2/FindPackagesById()?id='runtime.win-x64.runtime.native.System.Data.SqlClient.sni'&semVerLevel=2.0.0
info :   GET https://www.nuget.org/api/v2/FindPackagesById()?id='runtime.win-x86.runtime.native.System.Data.SqlClient.sni'&semVerLevel=2.0.0
info :   GET https://www.nuget.org/api/v2/package/System.Security.AccessControl/4.5.0
info :   OK https://www.nuget.org/api/v2/package/System.Text.Encoding.CodePages/4.5.0 174ms
info :   GET https://www.nuget.org/api/v2/FindPackagesById()?id='Microsoft.NETCore.Platforms'&semVerLevel=2.0.0
info :   GET https://www.nuget.org/api/v2/FindPackagesById()?id='System.Runtime.CompilerServices.Unsafe'&semVerLevel=2.0.0
info :   OK https://www.nuget.org/api/v2/package/Microsoft.Identity.Client/3.0.8 133ms
info :   GET https://www.nuget.org/api/v2/FindPackagesById()?id='Microsoft.CSharp'&semVerLevel=2.0.0
info :   GET https://www.nuget.org/api/v2/FindPackagesById()?id='System.ComponentModel.TypeConverter'&semVerLevel=2.0.0
info :   GET https://www.nuget.org/api/v2/FindPackagesById()?id='System.Net.NameResolution'&semVerLevel=2.0.0
info :   GET https://www.nuget.org/api/v2/FindPackagesById()?id='System.Runtime.Serialization.Formatters'&semVerLevel=2.0.0
info :   GET https://www.nuget.org/api/v2/FindPackagesById()?id='System.Runtime.Serialization.Json'&semVerLevel=2.0.0
info :   GET https://www.nuget.org/api/v2/FindPackagesById()?id='System.Runtime.Serialization.Primitives'&semVerLevel=2.0.0
info :   GET https://www.nuget.org/api/v2/FindPackagesById()?id='System.Security.SecureString'&semVerLevel=2.0.0
info :   GET https://www.nuget.org/api/v2/FindPackagesById()?id='System.Xml.XDocument'&semVerLevel=2.0.0
info :   OK https://www.nuget.org/api/v2/package/System.Security.AccessControl/4.5.0 126ms
info :   OK https://www.nuget.org/api/v2/FindPackagesById()?id='System.Runtime.CompilerServices.Unsafe'&semVerLevel=2.0.0 232ms
info :   OK https://www.nuget.org/api/v2/FindPackagesById()?id='Microsoft.NETCore.Platforms'&semVerLevel=2.0.0 256ms
info :   OK https://www.nuget.org/api/v2/FindPackagesById()?id='runtime.win-x64.runtime.native.System.Data.SqlClient.sni'&semVerLevel=2.0.0 385ms
info :   GET https://www.nuget.org/api/v2/package/runtime.win-x64.runtime.native.System.Data.SqlClient.sni/4.4.0
info :   OK https://www.nuget.org/api/v2/FindPackagesById()?id='runtime.win-x86.runtime.native.System.Data.SqlClient.sni'&semVerLevel=2.0.0 412ms
info :   GET https://www.nuget.org/api/v2/package/runtime.win-x86.runtime.native.System.Data.SqlClient.sni/4.4.0
info :   OK https://www.nuget.org/api/v2/FindPackagesById()?id='runtime.win-arm64.runtime.native.System.Data.SqlClient.sni'&semVerLevel=2.0.0 448ms
info :   OK https://www.nuget.org/api/v2/FindPackagesById()?id='System.Runtime.Caching'&semVerLevel=2.0.0 1113ms
info :   OK https://www.nuget.org/api/v2/FindPackagesById()?id='System.Configuration.ConfigurationManager'&semVerLevel=2.0.0 1115ms
info :   GET https://www.nuget.org/api/v2/package/runtime.win-arm64.runtime.native.System.Data.SqlClient.sni/4.4.0
info :   GET https://www.nuget.org/api/v2/package/Microsoft.NETCore.Platforms/2.0.0
info :   GET https://www.nuget.org/api/v2/package/System.Runtime.CompilerServices.Unsafe/4.5.0
info :   OK https://www.nuget.org/api/v2/package/runtime.win-x86.runtime.native.System.Data.SqlClient.sni/4.4.0 113ms
info :   OK https://www.nuget.org/api/v2/FindPackagesById()?id='System.Security.Principal.Windows'&semVerLevel=2.0.0 1207ms
info :   OK https://www.nuget.org/api/v2/FindPackagesById()?id='System.Runtime.Serialization.Formatters'&semVerLevel=2.0.0 365ms
info :   GET https://www.nuget.org/api/v2/package/System.Runtime.Caching/4.5.0
info :   OK https://www.nuget.org/api/v2/package/runtime.win-x64.runtime.native.System.Data.SqlClient.sni/4.4.0 193ms
info :   GET https://www.nuget.org/api/v2/package/System.Configuration.ConfigurationManager/4.5.0
info :   OK https://www.nuget.org/api/v2/FindPackagesById()?id='System.Runtime.Serialization.Json'&semVerLevel=2.0.0 403ms
info :   OK https://www.nuget.org/api/v2/FindPackagesById()?id='System.Net.NameResolution'&semVerLevel=2.0.0 412ms
info :   OK https://www.nuget.org/api/v2/FindPackagesById()?id='System.Security.SecureString'&semVerLevel=2.0.0 415ms
info :   OK https://www.nuget.org/api/v2/package/Microsoft.NETCore.Platforms/2.0.0 122ms
info :   OK https://www.nuget.org/api/v2/FindPackagesById()?id='System.Xml.XDocument'&semVerLevel=2.0.0 438ms
info :   OK https://www.nuget.org/api/v2/FindPackagesById()?id='System.Runtime.Serialization.Primitives'&semVerLevel=2.0.0 476ms
info :   OK https://www.nuget.org/api/v2/FindPackagesById()?id='Microsoft.CSharp'&semVerLevel=2.0.0 486ms
info :   OK https://www.nuget.org/api/v2/FindPackagesById()?id='System.ComponentModel.TypeConverter'&semVerLevel=2.0.0 483ms
info :   GET https://www.nuget.org/api/v2/package/System.Security.Principal.Windows/4.5.0
info :   OK https://www.nuget.org/api/v2/package/System.Runtime.CompilerServices.Unsafe/4.5.0 153ms
info :   GET https://www.nuget.org/api/v2/package/System.Runtime.Serialization.Formatters/4.3.0
info :   GET https://www.nuget.org/api/v2/package/System.Runtime.Serialization.Json/4.3.0
info :   GET https://www.nuget.org/api/v2/package/System.Net.NameResolution/4.3.0
info :   OK https://www.nuget.org/api/v2/package/System.Configuration.ConfigurationManager/4.5.0 116ms
info :   GET https://www.nuget.org/api/v2/package/System.Security.SecureString/4.3.0
info :   OK https://www.nuget.org/api/v2/package/System.Runtime.Caching/4.5.0 123ms
info :   GET https://www.nuget.org/api/v2/FindPackagesById()?id='System.Security.Cryptography.ProtectedData'&semVerLevel=2.0.0
info :   GET https://www.nuget.org/api/v2/FindPackagesById()?id='System.Security.Permissions'&semVerLevel=2.0.0
info :   GET https://www.nuget.org/api/v2/package/System.Xml.XDocument/4.3.0
info :   GET https://www.nuget.org/api/v2/package/System.Runtime.Serialization.Primitives/4.3.0
info :   GET https://www.nuget.org/api/v2/package/System.ComponentModel.TypeConverter/4.3.0
info :   GET https://www.nuget.org/api/v2/package/Microsoft.CSharp/4.5.0
info :   OK https://www.nuget.org/api/v2/package/System.Runtime.Serialization.Formatters/4.3.0 129ms
info :   OK https://www.nuget.org/api/v2/package/System.Security.Principal.Windows/4.5.0 135ms
info :   GET https://www.nuget.org/api/v2/FindPackagesById()?id='System.Collections'&semVerLevel=2.0.0
info :   GET https://www.nuget.org/api/v2/FindPackagesById()?id='System.Reflection'&semVerLevel=2.0.0
info :   GET https://www.nuget.org/api/v2/FindPackagesById()?id='System.Resources.ResourceManager'&semVerLevel=2.0.0
info :   GET https://www.nuget.org/api/v2/FindPackagesById()?id='System.Runtime'&semVerLevel=2.0.0
info :   OK https://www.nuget.org/api/v2/package/System.Security.SecureString/4.3.0 118ms
info :   OK https://www.nuget.org/api/v2/package/System.Runtime.Serialization.Json/4.3.0 127ms
info :   GET https://www.nuget.org/api/v2/FindPackagesById()?id='System.IO'&semVerLevel=2.0.0
info :   GET https://www.nuget.org/api/v2/package/Microsoft.NETCore.Platforms/1.1.0
info :   GET https://www.nuget.org/api/v2/FindPackagesById()?id='System.Private.DataContractSerialization'&semVerLevel=2.0.0
info :   GET https://www.nuget.org/api/v2/FindPackagesById()?id='System.Runtime.Handles'&semVerLevel=2.0.0
info :   GET https://www.nuget.org/api/v2/FindPackagesById()?id='System.Runtime.InteropServices'&semVerLevel=2.0.0
info :   GET https://www.nuget.org/api/v2/FindPackagesById()?id='System.Security.Cryptography.Primitives'&semVerLevel=2.0.0
info :   OK https://www.nuget.org/api/v2/package/System.Net.NameResolution/4.3.0 140ms
info :   GET https://www.nuget.org/api/v2/FindPackagesById()?id='System.Text.Encoding'&semVerLevel=2.0.0
info :   GET https://www.nuget.org/api/v2/FindPackagesById()?id='System.Threading'&semVerLevel=2.0.0
info :   GET https://www.nuget.org/api/v2/FindPackagesById()?id='runtime.native.System'&semVerLevel=2.0.0
info :   GET https://www.nuget.org/api/v2/FindPackagesById()?id='System.Diagnostics.Tracing'&semVerLevel=2.0.0
info :   GET https://www.nuget.org/api/v2/FindPackagesById()?id='System.Globalization'&semVerLevel=2.0.0
info :   GET https://www.nuget.org/api/v2/FindPackagesById()?id='System.Net.Primitives'&semVerLevel=2.0.0
info :   GET https://www.nuget.org/api/v2/FindPackagesById()?id='System.Runtime.Extensions'&semVerLevel=2.0.0
info :   GET https://www.nuget.org/api/v2/FindPackagesById()?id='System.Threading.Tasks'&semVerLevel=2.0.0
info :   OK https://www.nuget.org/api/v2/package/System.ComponentModel.TypeConverter/4.3.0 121ms
info :   OK https://www.nuget.org/api/v2/package/System.Runtime.Serialization.Primitives/4.3.0 129ms
info :   OK https://www.nuget.org/api/v2/package/System.Xml.XDocument/4.3.0 149ms
info :   GET https://www.nuget.org/api/v2/FindPackagesById()?id='System.Collections.NonGeneric'&semVerLevel=2.0.0
info :   GET https://www.nuget.org/api/v2/FindPackagesById()?id='System.Collections.Specialized'&semVerLevel=2.0.0
info :   GET https://www.nuget.org/api/v2/FindPackagesById()?id='System.ComponentModel'&semVerLevel=2.0.0
info :   GET https://www.nuget.org/api/v2/FindPackagesById()?id='System.ComponentModel.Primitives'&semVerLevel=2.0.0
info :   GET https://www.nuget.org/api/v2/FindPackagesById()?id='System.Linq'&semVerLevel=2.0.0
info :   OK https://www.nuget.org/api/v2/package/Microsoft.CSharp/4.5.0 134ms
info :   GET https://www.nuget.org/api/v2/FindPackagesById()?id='System.Reflection.Extensions'&semVerLevel=2.0.0
info :   GET https://www.nuget.org/api/v2/FindPackagesById()?id='System.Reflection.Primitives'&semVerLevel=2.0.0
info :   GET https://www.nuget.org/api/v2/FindPackagesById()?id='System.Reflection.TypeExtensions'&semVerLevel=2.0.0
info :   GET https://www.nuget.org/api/v2/FindPackagesById()?id='System.Diagnostics.Debug'&semVerLevel=2.0.0
info :   GET https://www.nuget.org/api/v2/FindPackagesById()?id='System.Diagnostics.Tools'&semVerLevel=2.0.0
info :   GET https://www.nuget.org/api/v2/FindPackagesById()?id='System.Xml.ReaderWriter'&semVerLevel=2.0.0
info :   OK https://www.nuget.org/api/v2/FindPackagesById()?id='System.Security.Cryptography.ProtectedData'&semVerLevel=2.0.0 205ms
info :   OK https://www.nuget.org/api/v2/FindPackagesById()?id='System.Security.Permissions'&semVerLevel=2.0.0 209ms
info :   OK https://www.nuget.org/api/v2/FindPackagesById()?id='System.Runtime.InteropServices'&semVerLevel=2.0.0 113ms
info :   OK https://www.nuget.org/api/v2/package/Microsoft.NETCore.Platforms/1.1.0 122ms
info :   OK https://www.nuget.org/api/v2/FindPackagesById()?id='System.Resources.ResourceManager'&semVerLevel=2.0.0 178ms
info :   OK https://www.nuget.org/api/v2/FindPackagesById()?id='System.Reflection'&semVerLevel=2.0.0 192ms
info :   OK https://www.nuget.org/api/v2/package/runtime.win-arm64.runtime.native.System.Data.SqlClient.sni/4.4.0 556ms
info :   GET https://www.nuget.org/api/v2/package/System.Security.Cryptography.ProtectedData/4.5.0
info :   GET https://www.nuget.org/api/v2/package/System.Security.Permissions/4.5.0
info :   OK https://www.nuget.org/api/v2/FindPackagesById()?id='System.Collections'&semVerLevel=2.0.0 223ms
info :   OK https://www.nuget.org/api/v2/FindPackagesById()?id='System.IO'&semVerLevel=2.0.0 202ms
info :   GET https://www.nuget.org/api/v2/package/System.Runtime.InteropServices/4.3.0
info :   OK https://www.nuget.org/api/v2/FindPackagesById()?id='System.Runtime'&semVerLevel=2.0.0 253ms
info :   OK https://www.nuget.org/api/v2/FindPackagesById()?id='System.Collections.Specialized'&semVerLevel=2.0.0 183ms
info :   OK https://www.nuget.org/api/v2/FindPackagesById()?id='System.Private.DataContractSerialization'&semVerLevel=2.0.0 243ms
info :   OK https://www.nuget.org/api/v2/FindPackagesById()?id='System.Security.Cryptography.Primitives'&semVerLevel=2.0.0 245ms
info :   OK https://www.nuget.org/api/v2/FindPackagesById()?id='System.Runtime.Handles'&semVerLevel=2.0.0 254ms
info :   OK https://www.nuget.org/api/v2/FindPackagesById()?id='System.ComponentModel'&semVerLevel=2.0.0 205ms
info :   OK https://www.nuget.org/api/v2/FindPackagesById()?id='System.Text.Encoding'&semVerLevel=2.0.0 262ms
info :   OK https://www.nuget.org/api/v2/FindPackagesById()?id='System.Collections.NonGeneric'&semVerLevel=2.0.0 230ms
info :   OK https://www.nuget.org/api/v2/FindPackagesById()?id='System.ComponentModel.Primitives'&semVerLevel=2.0.0 232ms
info :   GET https://www.nuget.org/api/v2/package/System.Resources.ResourceManager/4.3.0
info :   GET https://www.nuget.org/api/v2/package/System.Reflection/4.3.0
info :   GET https://www.nuget.org/api/v2/package/System.Collections/4.3.0
info :   GET https://www.nuget.org/api/v2/package/System.IO/4.3.0
info :   GET https://www.nuget.org/api/v2/package/System.Collections.Specialized/4.3.0
info :   GET https://www.nuget.org/api/v2/package/System.Private.DataContractSerialization/4.3.0
info :   GET https://www.nuget.org/api/v2/package/System.Security.Cryptography.Primitives/4.3.0
info :   OK https://www.nuget.org/api/v2/package/System.Security.Permissions/4.5.0 170ms
info :   GET https://www.nuget.org/api/v2/package/System.Runtime.Handles/4.3.0
info :   OK https://www.nuget.org/api/v2/package/System.Runtime.InteropServices/4.3.0 139ms
info :   GET https://www.nuget.org/api/v2/package/System.ComponentModel/4.3.0
info :   OK https://www.nuget.org/api/v2/package/System.Security.Cryptography.ProtectedData/4.5.0 186ms
info :   GET https://www.nuget.org/api/v2/package/System.Collections.NonGeneric/4.3.0
info :   GET https://www.nuget.org/api/v2/package/System.Text.Encoding/4.3.0
info :   GET https://www.nuget.org/api/v2/FindPackagesById()?id='Microsoft.NETCore.Targets'&semVerLevel=2.0.0
info :   OK https://www.nuget.org/api/v2/FindPackagesById()?id='System.Diagnostics.Tracing'&semVerLevel=2.0.0 398ms
info :   OK https://www.nuget.org/api/v2/FindPackagesById()?id='runtime.native.System'&semVerLevel=2.0.0 400ms
info :   OK https://www.nuget.org/api/v2/FindPackagesById()?id='System.Threading'&semVerLevel=2.0.0 417ms
info :   OK https://www.nuget.org/api/v2/FindPackagesById()?id='System.Globalization'&semVerLevel=2.0.0 657ms
info :   GET https://www.nuget.org/api/v2/package/System.ComponentModel.Primitives/4.3.0
info :   OK https://www.nuget.org/api/v2/FindPackagesById()?id='System.Runtime.Extensions'&semVerLevel=2.0.0 656ms
info :   OK https://www.nuget.org/api/v2/FindPackagesById()?id='System.Reflection.Primitives'&semVerLevel=2.0.0 614ms
info :   OK https://www.nuget.org/api/v2/FindPackagesById()?id='System.Linq'&semVerLevel=2.0.0 720ms
info :   OK https://www.nuget.org/api/v2/FindPackagesById()?id='System.Reflection.Extensions'&semVerLevel=2.0.0 723ms
info :   OK https://www.nuget.org/api/v2/FindPackagesById()?id='System.Net.Primitives'&semVerLevel=2.0.0 768ms
info :   GET https://www.nuget.org/api/v2/package/System.Runtime/4.3.0
info :   GET https://www.nuget.org/api/v2/package/System.Threading/4.3.0
info :   GET https://www.nuget.org/api/v2/package/runtime.native.System/4.3.0
info :   OK https://www.nuget.org/api/v2/FindPackagesById()?id='System.Xml.ReaderWriter'&semVerLevel=2.0.0 1378ms
info :   GET https://www.nuget.org/api/v2/package/System.Diagnostics.Tracing/4.3.0
info :   OK https://www.nuget.org/api/v2/FindPackagesById()?id='System.Diagnostics.Debug'&semVerLevel=2.0.0 1385ms
info :   OK https://www.nuget.org/api/v2/FindPackagesById()?id='System.Threading.Tasks'&semVerLevel=2.0.0 1436ms
info :   OK https://www.nuget.org/api/v2/FindPackagesById()?id='System.Reflection.TypeExtensions'&semVerLevel=2.0.0 1394ms
info :   OK https://www.nuget.org/api/v2/FindPackagesById()?id='Microsoft.NETCore.Targets'&semVerLevel=2.0.0 1050ms
info :   OK https://www.nuget.org/api/v2/FindPackagesById()?id='System.Diagnostics.Tools'&semVerLevel=2.0.0 1385ms
info :   GET https://www.nuget.org/api/v2/package/System.Runtime.Extensions/4.3.0
info :   OK https://www.nuget.org/api/v2/package/System.Private.DataContractSerialization/4.3.0 1147ms
info :   OK https://www.nuget.org/api/v2/package/System.Security.Cryptography.Primitives/4.3.0 1149ms
info :   OK https://www.nuget.org/api/v2/package/System.Resources.ResourceManager/4.3.0 1157ms
info :   OK https://www.nuget.org/api/v2/package/System.Reflection/4.3.0 1143ms
info :   OK https://www.nuget.org/api/v2/package/System.Collections.Specialized/4.3.0 1129ms
info :   OK https://www.nuget.org/api/v2/package/System.Collections/4.3.0 1119ms
info :   GET https://www.nuget.org/api/v2/package/System.Reflection.Extensions/4.3.0
info :   OK https://www.nuget.org/api/v2/package/System.IO/4.3.0 1131ms
info :   OK https://www.nuget.org/api/v2/package/System.Collections.NonGeneric/4.3.0 1134ms
info :   OK https://www.nuget.org/api/v2/package/System.Runtime.Handles/4.3.0 1152ms
info :   OK https://www.nuget.org/api/v2/package/System.Text.Encoding/4.3.0 1133ms
info :   GET https://www.nuget.org/api/v2/package/System.Net.Primitives/4.3.0
info :   OK https://www.nuget.org/api/v2/package/System.ComponentModel/4.3.0 1147ms
info :   OK https://www.nuget.org/api/v2/package/System.ComponentModel.Primitives/4.3.0 859ms
info :   GET https://www.nuget.org/api/v2/package/System.Reflection.Primitives/4.3.0
info :   GET https://www.nuget.org/api/v2/package/System.Globalization/4.3.0
info :   GET https://www.nuget.org/api/v2/package/System.Reflection.TypeExtensions/4.3.0
info :   GET https://www.nuget.org/api/v2/package/Microsoft.NETCore.Targets/1.1.0
info :   GET https://www.nuget.org/api/v2/package/System.Threading.Tasks/4.3.0
info :   GET https://www.nuget.org/api/v2/package/System.Diagnostics.Debug/4.3.0
info :   GET https://www.nuget.org/api/v2/FindPackagesById()?id='System.Collections.Concurrent'&semVerLevel=2.0.0
info :   GET https://www.nuget.org/api/v2/package/System.Xml.ReaderWriter/4.3.0
info :   GET https://www.nuget.org/api/v2/FindPackagesById()?id='System.Reflection.Emit.ILGeneration'&semVerLevel=2.0.0
info :   GET https://www.nuget.org/api/v2/package/System.Linq/4.3.0
info :   GET https://www.nuget.org/api/v2/FindPackagesById()?id='System.Reflection.Emit.Lightweight'&semVerLevel=2.0.0
info :   GET https://www.nuget.org/api/v2/FindPackagesById()?id='System.Text.Encoding.Extensions'&semVerLevel=2.0.0
info :   GET https://www.nuget.org/api/v2/FindPackagesById()?id='System.Text.RegularExpressions'&semVerLevel=2.0.0
info :   GET https://www.nuget.org/api/v2/FindPackagesById()?id='System.Xml.XmlDocument'&semVerLevel=2.0.0
info :   GET https://www.nuget.org/api/v2/FindPackagesById()?id='System.Xml.XmlSerializer'&semVerLevel=2.0.0
info :   GET https://www.nuget.org/api/v2/package/System.Diagnostics.Tools/4.3.0
info :   OK https://www.nuget.org/api/v2/package/System.Runtime/4.3.0 122ms
info :   OK https://www.nuget.org/api/v2/package/runtime.native.System/4.3.0 130ms
info :   OK https://www.nuget.org/api/v2/package/System.Diagnostics.Tracing/4.3.0 149ms
info :   GET https://www.nuget.org/api/v2/FindPackagesById()?id='System.Globalization.Extensions'&semVerLevel=2.0.0
info :   OK https://www.nuget.org/api/v2/package/System.Runtime.Extensions/4.3.0 162ms
info :   OK https://www.nuget.org/api/v2/package/System.Threading/4.3.0 185ms
info :   OK https://www.nuget.org/api/v2/package/System.Reflection.Extensions/4.3.0 132ms
info :   OK https://www.nuget.org/api/v2/package/System.Globalization/4.3.0 114ms
info :   OK https://www.nuget.org/api/v2/package/System.Net.Primitives/4.3.0 127ms
info :   OK https://www.nuget.org/api/v2/package/Microsoft.NETCore.Targets/1.1.0 117ms
info :   OK https://www.nuget.org/api/v2/package/System.Reflection.Primitives/4.3.0 136ms
info :   OK https://www.nuget.org/api/v2/package/System.Diagnostics.Debug/4.3.0 196ms
info :   OK https://www.nuget.org/api/v2/package/System.Reflection.TypeExtensions/4.3.0 206ms
info :   OK https://www.nuget.org/api/v2/FindPackagesById()?id='System.Text.RegularExpressions'&semVerLevel=2.0.0 187ms
info :   OK https://www.nuget.org/api/v2/package/System.Threading.Tasks/4.3.0 202ms
info :   OK https://www.nuget.org/api/v2/package/System.Linq/4.3.0 195ms
info :   OK https://www.nuget.org/api/v2/FindPackagesById()?id='System.Reflection.Emit.ILGeneration'&semVerLevel=2.0.0 269ms
info :   OK https://www.nuget.org/api/v2/FindPackagesById()?id='System.Collections.Concurrent'&semVerLevel=2.0.0 277ms
info :   OK https://www.nuget.org/api/v2/FindPackagesById()?id='System.Reflection.Emit.Lightweight'&semVerLevel=2.0.0 273ms
info :   OK https://www.nuget.org/api/v2/FindPackagesById()?id='System.Text.Encoding.Extensions'&semVerLevel=2.0.0 273ms
info :   OK https://www.nuget.org/api/v2/FindPackagesById()?id='System.Xml.XmlDocument'&semVerLevel=2.0.0 278ms
info :   OK https://www.nuget.org/api/v2/FindPackagesById()?id='System.Xml.XmlSerializer'&semVerLevel=2.0.0 283ms
info :   OK https://www.nuget.org/api/v2/FindPackagesById()?id='System.Globalization.Extensions'&semVerLevel=2.0.0 246ms
info :   OK https://www.nuget.org/api/v2/package/System.Xml.ReaderWriter/4.3.0 366ms
info :   OK https://www.nuget.org/api/v2/package/System.Diagnostics.Tools/4.3.0 535ms
info :   GET https://www.nuget.org/api/v2/package/System.Collections.Concurrent/4.3.0
info :   GET https://www.nuget.org/api/v2/package/System.Reflection.Emit.ILGeneration/4.3.0
info :   GET https://www.nuget.org/api/v2/package/System.Text.RegularExpressions/4.3.0
info :   GET https://www.nuget.org/api/v2/package/System.Reflection.Emit.Lightweight/4.3.0
info :   GET https://www.nuget.org/api/v2/package/System.Xml.XmlDocument/4.3.0
info :   GET https://www.nuget.org/api/v2/package/System.Xml.XmlSerializer/4.3.0
info :   GET https://www.nuget.org/api/v2/package/System.Globalization.Extensions/4.3.0
info :   GET https://www.nuget.org/api/v2/package/System.Text.Encoding.Extensions/4.3.0
info :   GET https://www.nuget.org/api/v2/FindPackagesById()?id='System.IO.FileSystem'&semVerLevel=2.0.0
info :   GET https://www.nuget.org/api/v2/FindPackagesById()?id='System.IO.FileSystem.Primitives'&semVerLevel=2.0.0
info :   GET https://www.nuget.org/api/v2/FindPackagesById()?id='System.Threading.Tasks.Extensions'&semVerLevel=2.0.0
info :   OK https://www.nuget.org/api/v2/package/System.Text.RegularExpressions/4.3.0 133ms
info :   OK https://www.nuget.org/api/v2/package/System.Xml.XmlDocument/4.3.0 126ms
info :   OK https://www.nuget.org/api/v2/package/System.Globalization.Extensions/4.3.0 123ms
info :   OK https://www.nuget.org/api/v2/package/System.Reflection.Emit.ILGeneration/4.3.0 167ms
info :   OK https://www.nuget.org/api/v2/package/System.Reflection.Emit.Lightweight/4.3.0 146ms
info :   OK https://www.nuget.org/api/v2/package/System.Collections.Concurrent/4.3.0 192ms
info :   OK https://www.nuget.org/api/v2/package/System.Xml.XmlSerializer/4.3.0 152ms
info :   GET https://www.nuget.org/api/v2/FindPackagesById()?id='System.Reflection.Emit'&semVerLevel=2.0.0
info :   OK https://www.nuget.org/api/v2/package/System.Text.Encoding.Extensions/4.3.0 152ms
info :   OK https://www.nuget.org/api/v2/FindPackagesById()?id='System.IO.FileSystem'&semVerLevel=2.0.0 176ms
info :   OK https://www.nuget.org/api/v2/FindPackagesById()?id='System.IO.FileSystem.Primitives'&semVerLevel=2.0.0 210ms
info :   OK https://www.nuget.org/api/v2/FindPackagesById()?id='System.Threading.Tasks.Extensions'&semVerLevel=2.0.0 232ms
info :   GET https://www.nuget.org/api/v2/package/System.IO.FileSystem/4.3.0
info :   GET https://www.nuget.org/api/v2/package/System.IO.FileSystem.Primitives/4.3.0
info :   GET https://www.nuget.org/api/v2/package/System.Threading.Tasks.Extensions/4.3.0
info :   OK https://www.nuget.org/api/v2/FindPackagesById()?id='System.Reflection.Emit'&semVerLevel=2.0.0 250ms
info :   OK https://www.nuget.org/api/v2/package/System.IO.FileSystem.Primitives/4.3.0 123ms
info :   OK https://www.nuget.org/api/v2/package/System.IO.FileSystem/4.3.0 164ms
info :   OK https://www.nuget.org/api/v2/package/System.Threading.Tasks.Extensions/4.3.0 113ms
info :   GET https://www.nuget.org/api/v2/package/System.Reflection.Emit/4.3.0
info :   OK https://www.nuget.org/api/v2/package/System.Reflection.Emit/4.3.0 124ms
info : Installing System.Reflection.Emit 4.3.0.
info : Installing System.Xml.XmlSerializer 4.3.0.
info : Installing System.Collections.Concurrent 4.3.0.
info : Installing System.Reflection.Emit.Lightweight 4.3.0.
info : Installing System.Reflection.Emit.ILGeneration 4.3.0.
info : Installing System.Xml.XmlDocument 4.3.0.
info : Installing System.Threading.Tasks.Extensions 4.3.0.
info : Installing System.IO.FileSystem 4.3.0.
info : Installing System.IO.FileSystem.Primitives 4.3.0.
info : Installing System.Text.Encoding.Extensions 4.3.0.
info : Installing System.Text.RegularExpressions 4.3.0.
info : Installing System.Globalization.Extensions 4.3.0.
info : Installing Microsoft.NETCore.Targets 1.1.0.
info : Installing System.Private.DataContractSerialization 4.3.0.
info : Installing System.Xml.ReaderWriter 4.3.0.
info : Installing System.Diagnostics.Tools 4.3.0.
info : Installing Microsoft.Data.SqlClient 1.0.19269.1.
info : Installing System.IO 4.3.0.
info : Installing Microsoft.Win32.Registry 4.5.0.
info : Installing System.Text.Encoding.CodePages 4.5.0.
info : Installing System.Runtime.Caching 4.5.0.
info : Installing System.Security.Principal.Windows 4.5.0.
info : Installing runtime.native.System.Data.SqlClient.sni 4.4.0.
info : Installing System.Configuration.ConfigurationManager 4.5.0.
info : Installing Microsoft.Identity.Client 3.0.8.
info : Installing System.Diagnostics.Debug 4.3.0.
info : Installing System.Security.AccessControl 4.5.0.
info : Installing Microsoft.NETCore.Platforms 2.0.0.
info : Installing System.Runtime.CompilerServices.Unsafe 4.5.0.
info : Installing runtime.win-x86.runtime.native.System.Data.SqlClient.sni 4.4.0.
info : Installing runtime.win-x64.runtime.native.System.Data.SqlClient.sni 4.4.0.
info : Installing runtime.win-arm64.runtime.native.System.Data.SqlClient.sni 4.4.0.
info : Installing System.Security.Permissions 4.5.0.
info : Installing System.Security.Cryptography.ProtectedData 4.5.0.
info : Installing Microsoft.CSharp 4.5.0.
info : Installing System.Runtime.Serialization.Formatters 4.3.0.
info : Installing System.Runtime.Serialization.Primitives 4.3.0.
info : Installing System.Security.SecureString 4.3.0.
info : Installing System.Net.NameResolution 4.3.0.
info : Installing System.ComponentModel.TypeConverter 4.3.0.
info : Installing System.Xml.XDocument 4.3.0.
info : Installing System.Runtime.Serialization.Json 4.3.0.
info : Installing System.Collections 4.3.0.
info : Installing System.Resources.ResourceManager 4.3.0.
info : Installing System.Runtime 4.3.0.
info : Installing System.Collections.Specialized 4.3.0.
info : Installing System.Reflection 4.3.0.
info : Installing Microsoft.NETCore.Platforms 1.1.0.
info : Installing System.Text.Encoding 4.3.0.
info : Installing System.Runtime.Handles 4.3.0.
info : Installing System.Runtime.InteropServices 4.3.0.
info : Installing System.Security.Cryptography.Primitives 4.3.0.
info : Installing System.Threading 4.3.0.
info : Installing System.Globalization 4.3.0.
info : Installing System.Linq 4.3.0.
info : Installing System.Runtime.Extensions 4.3.0.
info : Installing System.Diagnostics.Tracing 4.3.0.
info : Installing runtime.native.System 4.3.0.
info : Installing System.Net.Primitives 4.3.0.
info : Installing System.Threading.Tasks 4.3.0.
info : Installing System.ComponentModel.Primitives 4.3.0.
info : Installing System.ComponentModel 4.3.0.
info : Installing System.Collections.NonGeneric 4.3.0.
info : Installing System.Reflection.TypeExtensions 4.3.0.
info : Installing System.Reflection.Extensions 4.3.0.
info : Installing System.Reflection.Primitives 4.3.0.
info : Package 'Microsoft.Data.SqlClient' is compatible with all the specified frameworks in project 'C:\proj\proj.csproj'.
info : PackageReference for package 'Microsoft.Data.SqlClient' version '1.0.19269.1' added to file 'C:\proj\proj.csproj'.
info : Committing restore...
info : Writing assets file to disk. Path: C:\proj\obj\project.assets.json
log  : Restore completed in 14.36 sec for C:\proj\proj.csproj.
@lancer-xue
Copy link

Hi Martin, I am testing Microsoft.data.sqlclient in powershell recently and I have followed your post above, but it did not work for me. Somehow, the command "Install-Package Microsoft.Data.SqlClient" does not work, it is just hanging there without any output. To workaround this, I installed Microsoft.Data.SqlClient through VS. From there, I am not sure how to add type in powershell. Is there any suggestion?
Thanks in advanced.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment