Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'The specified invariant name 'System.Data.SqlClient' wasn't found in the list of registered .NET Data Providers.' on a .netCore project

I am getting the error above on a .netCore API project that's referencing .netCore library that connects to a SQL database. Can anyone help me here? I have already referenced the System.Data.SQLClient or Microsoft.Data.SqlClient and still no luck.

Thanks,

Herbert

like image 251
the.herbert Avatar asked Jun 08 '20 04:06

the.herbert


1 Answers

There is no global configuration (commonly known as GAC) in .NET Core. As a result, the provider is not registered by default. You will have to manually register the provider. You can register it as

DbProviderFactories.RegisterFactory("System.Data.SqlClient", System.Data.SqlClient.SqlClientFactory.Instance);

//for Connection
var factory = DbProviderFactories.GetFactory("System.Data.SqlClient");
DbConnection connection = factory.CreateConnection();
like image 138
rabink Avatar answered Nov 14 '22 01:11

rabink