无法找到请求的 .Net Framework 数据提供程序。它可能没有安装

Unable to find the requested .Net Framework Data Provider. It may not be installed

我知道有很多帖子有这个错误,但我不是从 MVC 项目中得到这个错误的。我创建了一个简单的 ASP.net 空网站,然后添加了 app_Data 文件夹,创建了 SQL 数据库,添加了一个 table,然后我创建了一个 Web 表单。每当我尝试 运行 应用程序时,都会弹出此错误。我觉得这真的很奇怪,因为我可以 运行 其他 ASP.NET 项目,比如 MVC 完全没有问题,而且数据提供者是相同的,我仔细检查过。无论如何,这是信息:

<connectionStrings>
    <add name="principal" connectionString="Data Source=(LocalDB)\v11.0;AttachDbFileName=|DataDirectory|\Database.mdf;Integrated Security=True" providerName="System.Data.SqlClient" />
  </connectionStrings>

数据库名称正确,我仔细检查过。另外,我有另一个项目具有完全相同的连接字符串并且它可以工作(但它不是 asp.net 形式,它是一个 mvc 项目)

关于错误的信息:

Unable to find the requested .Net Framework Data Provider.  It may not be installed.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.ArgumentException: Unable to find the requested .Net Framework Data Provider.  It may not be installed.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace: 


[ArgumentException: Unable to find the requested .Net Framework Data Provider.  It may not be installed.]
   System.Data.Common.DbProviderFactories.GetFactory(String providerInvariantName) +1442135
   System.Web.UI.WebControls.SqlDataSource.GetDbProviderFactory() +67
   System.Web.UI.WebControls.SqlDataSource.GetDbProviderFactorySecure() +22
   System.Web.UI.WebControls.SqlDataSource.CreateConnection(String connectionString) +11
   System.Web.UI.WebControls.SqlDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +113
   System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +21
   System.Web.UI.WebControls.DataBoundControl.PerformSelect() +138
   System.Web.UI.WebControls.ListView.PerformSelect() +167
   System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +30
   System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +105
   System.Web.UI.WebControls.ListView.CreateChildControls() +122
   System.Web.UI.Control.EnsureChildControls() +83
   System.Web.UI.Control.PreRenderRecursiveInternal() +42
   System.Web.UI.Control.PreRenderRecursiveInternal() +155
   System.Web.UI.Control.PreRenderRecursiveInternal() +155
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +974

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.34237

我能够解决我的问题,我不知道这是否是一个错误,但看起来是这样。我以前在我的 SQL 数据源中有这个:

<asp:SqlDataSource ID="MensagemSqlDataSource" runat="server"
            ConnectionString="<%$ ConnectionStrings:principal %>"
            ProviderName="<%$ ConnectionStrings:principal.ProviderName %>"
            SelectCommand="SELECT Codigo,Assunto FROM Mensagem WHERE Resposta IS NULL ORDER BY Codigo"
            DeleteCommand="DELETE FROM Mensagem WHERE Codigo = @Codigo">

//(...) doesn't matter the rest of the code (...)

因此 ProviderName 行指向 ConnectionStrings:principal.ProviderName, 是 "System.Data.SqlClient",如我在第一个 post 中所述。所以我只是将其更改为:

<asp:SqlDataSource ID="mensagemBlog"
             runat ="server" 
            ConnectionString ="<%$ ConnectionStrings:principal %>" 
            ProviderName ="System.Data.SqlClient" 
            SelectCommand ="SELECT Codigo,Assunto FROM Mensagem WHERE Resposta IS NULL ORDER BY Codigo"
            DeleteCommand="DELETE FROM Mensagem WHERE Codigo = @Codigo" >

它奏效了。 也许这是某种错误,或者我误解了该命令的工作原理。