Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I am developing .net core and angular web application. In this solution, we are calling the database using another class library in .net 5. So, When it coming to create a connection
It says below Error:

"
'System.Data.SqlClient' wasn't found in the list of registered .NET core Data Providers.'


Below is my DB Factory Class

using Microsoft.Extensions.Configuration;
using System.Configuration;
using System.Data.Common;

namespace Portal.DAL.DataAccess
{
    public class GenericDbFactory
    {
        protected const string ProviderInvarientName = "System.Data.SqlClient";

        public static DbProviderFactory Factory
        {
            get
            {
                return DbProviderFactories.GetFactory(ProviderInvarientName);
            }
        }

        public static DbConnection GetConnection(string dbName, IConfiguration configuration)
        {
            string ConnectionString = configuration.GetConnectionString("DefaultConnection");
            DbConnection Connection = Factory.CreateConnection();
            Connection.ConnectionString = ConnectionString;
            return Connection;
        }
    }
}


Please help me to solve this error.

Have a nice day!

What I have tried:

Tried with Microsoft documentation in data providers
Searched everywhere on the internet.
Posted
Updated 19-Jun-21 0:25am

I had the same problem - reason: with NET 5 the SQL client library isn't included by default. You habe to install it first with the nuget manager and for NET 5 it's no longer located in the main namespace "System" but in "Microsoft".
 
Share this answer
 
Comments
eweqee 19-Jun-21 6:16am    
Can you put your code sample here?

Thanks for the answering.
It's not a solution by code - you have to use the nuget manager in Visual Studio to add the reference.
 
Share this answer
 
Comments
Richard Deeming 21-Jun-21 10:32am    
If you want to reply to a comment, click the "Reply" button next to the comment. Do not post your reply as another solution.
NightWizzard 22-Jun-21 4:48am    
Be sure this won't happen any more. As long as anybody can downvote everbodies answers - given with the intention to help - for any lapidary reason, I don't share my experiences any longer.
Richard Deeming 22-Jun-21 4:51am    
If you can't cope with a little constructive criticism, then you're not going to get very far on the internet. Or in life in general for that matter. 🤣
NightWizzard 22-Jun-21 4:54am    
I can cope...but -16 points for a little mistake while answering isn't fair at all.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900