'在已注册的 .NET 数据提供程序列表中找不到指定的不变名称 'System.Data.SqlClient'.在 .netCore 项目上 [英] 'The specified invariant name 'System.Data.SqlClient' wasn't found in the list of registered .NET Data Providers.' on a .netCore project

查看:34
本文介绍了'在已注册的 .NET 数据提供程序列表中找不到指定的不变名称 'System.Data.SqlClient'.在 .netCore 项目上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在引用连接到 SQL 数据库的 .netCore 库的 .netCore API 项目中收到上述错误.有人能帮我一下吗?我已经引用了 System.Data.SQLClient 或 Microsoft.Data.SqlClient ,但仍然没有运气.

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.

谢谢,

赫伯特

推荐答案

.NET Core 中没有全局配置(俗称 GAC).因此,默认情况下未注册提供程序.您必须手动注册提供程序.你可以注册为

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();

这篇关于'在已注册的 .NET 数据提供程序列表中找不到指定的不变名称 'System.Data.SqlClient'.在 .netCore 项目上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆