SqlClientFactory.Instance is null when using Microsoft.Data.SqlClient in Jupyter C# Kernel
Describe the bug
I attempted to load data from a SQL Server DB using the DatabaseLoader from a Jupyter Notebook. I was first using System.Data.SqlClient as the ProviderFactory, but I got multiple re-direct issues in Jupyter. I moved to Microsoft.Data.SqlClient, which is supposed to work better with .NET Core and continued passed that issue. However, I instead run in to an issue where it says the provider factory is null.
Did this error occur while using dotnet try or online?
- [X]
dotnet-try - [ ] online
What kind of error was it?
- [ ] User Interface (UI): For example the output never displayed
- [ ] Service Error: For example "The service is temporarily unavailable. We are working on it"
- [X] Other:
Screenshots

Please complete the following:
- OS
- [X] Windows 10
- [ ] macOS
- [ ] Linux (Please specify distro)
- [ ] iOS
- [ ] Android
- Browser
- [X] Chrome
- [ ] Edge
- [ ] Safari
@aslotte not sure if this will help you, because you didn't post what package versions you might be using, and I was getting slightly different errors, But, I was able to get my scenario working by using:
#r "nuget:Microsoft.ML, 1.4.0"
#r "nuget:System.Data.SqlClient, 4.2.0"
using Microsoft.ML;
using Microsoft.ML.Data;
using System.Data.SqlClient;
While doing something similar, I had a potentially related issue. When I try to instantiate a SqlConnection in a Jupyter notebook from code that I've imported, I get a System.PlatformNotSupportedException.
I'm running a C# Jupyter notebook setup using dotnet-try on a Windows 10 machine and accessing it from Chrome.
I import a dll on my machine using #r "path/to/library.dll" that exposes a method that uses a System.Data.SqlClient to get some data from a DB, do some parsing, and return an IEnumerable of the results. When I call this function from the Jupyter notebook, a System.PlatformNotSupportedException is thrown when it reaches the new SqlConnection(connectionString) call. When I run the code from my machine it performs as expected.
I've tried changing the imported version of the SqlClient library around as @jaymclain suggested, but haven't had any luck so far. At first I thought the SqlClient was simply not yet supported by dotnet-try, but as jaymaclain got it working above, I'm wondering if the issue has to do with the indirect reference to the assembly.
@jaymclain - I was using Sql.Data.SqlClient v4.6.0. When I updated to use ML.NET v1.4.0 I got other issues, that it couldn't find Sql.Data.SqlClient v4.5.0, so I think I'm having redirect issues in Jupyter Notebook.
When I changed to using Sql.Data.SqlClient v4.2.0, it works as you mentioned. Do you know if ML.NET uses v4.2.0 and that's why v4.6.0 doesn't work?
@aslotte,
hi, I just tried to repro this with the latest master branch. We have done a ton of work on the package management, and it seems as if this now works fine.
Please reopen this, if you are still having trouble with this.
Thanks
Kevin

I am getting a null of SqlClientFactory.Instance (instance static field) in .net core 2.1, due to this i am not able to register the System.Data.SqlClient data provider in .net core 2.1.
DbProviderFactories.RegisterFactory( "System.Data.SqlClient", SqlClientFactory.Instance);
In .net core 3.1 it's working fine. but i am using .net core 2.1. could you help how register the SQL client data provider in .net core 2.1