无法确定“System.Data.SqlClient.SqlConnection”类型连接的 DbProviderFactory 类型

问题描述 投票:0回答:1

我有使用 EF 6.0 开发的 Asp.net MVC 应用程序。

当我从源代码运行它时,它工作得很好。但是当我在 Windows Server 2016 计算机上部署该应用程序时,它在页面上显示以下消息。

错误:从数据库获取提供商信息时发生错误。这可能是由于实体框架使用了不正确的连接字符串造成的。检查内部异常的详细信息并确保连接字符串正确。 :无法确定“System.Data.SqlClient.SqlConnection”类型连接的 DbProviderFactory 类型。确保 ADO.NET 提供程序已安装或在应用程序配置中注册。

有人可以帮我解决这个问题吗?

下面是应用程序的 web.config 文件。

<?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    <section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog" />
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="glimpse" type="Glimpse.Core.Configuration.Section, Glimpse.Core" />
  </configSections>
  <connectionStrings>



    <add name="TitanSQLConnection" connectionString="Data Source=ukpdpmc3;Initial Catalog=Titan;Integrated Security=True;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />
    <add name="TitanLiveSQLConnection" connectionString="Data Source=ukpdpmc3;Initial Catalog=Titan;Integrated Security=True;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />
    <add name="DMSSQLConnection" connectionString="data source=ukpdpmc3;initial catalog=DMS;integrated security=True;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />
    <add name="TitanTestSQLConnection" connectionString="Data Source=ukpdpmc3;Initial Catalog=Titan;Integrated Security=True;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />
    <!--<add name="ADConnectionString" connectionString="LDAP://ukpdc01.uk.nex.global/OU=IT,OU=Central Functions,OU=NEXUK Users,DC=uk,DC=nex,DC=global" />-->
    <add name="ADConnectionString" connectionString="LDAP://ukpdc01.uk.nex.global/DC=uk,DC=nex,DC=global" />
    <add name="PartnerDbSQLConnection" connectionString="Data Source=ukpdpmc3;Initial Catalog=PartnersDB;Integrated Security=True;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />
    <add name="PartnerLiveSQLConnection" connectionString="Data Source=ukpdpmc3;Initial Catalog=PartnersDB;Integrated Security=True;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />
    <add name="PartnerTestSQLConnection" connectionString="Data Source=ukpdpmc5;Initial Catalog=PartnersDB;Integrated Security=True;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />
    <add name="NXLookupSQLConnection" connectionString="Data Source=ukpdpmc3;Initial Catalog=NXlookup;Integrated Security=True;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />
  </connectionStrings>

  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="nxsmartapi_pub_SmartApi1_Binder">
          <readerQuotas  maxStringContentLength="65536" />
          <security mode="TransportCredentialOnly">
            <transport clientCredentialType="Basic" />
            <message clientCredentialType="UserName" algorithmSuite="Default" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://ukpdsagis4.uk.nex.global:306/ws/nxsmartapi.pub.SmartApi1/nxsmartapi_pub_SmartApi1_Port" binding="basicHttpBinding" bindingConfiguration="nxsmartapi_pub_SmartApi1_Binder" contract="SmartApi.SmartApi1_PortType" name="nxsmartapi_pub_SmartApi1_Port" />
    </client>
  </system.serviceModel>

  <appSettings>
    <add key="autoFormsAuthentication" value="false" />
    <add key="enableSimpleMembership" value="false" />
    <!--<add key="ADDOMAIN" value="ukpdc01.uk.nex.global" />-->
    <add key="webpages:Version" value="2.0.0.0" />
    <add key="webpages:Enabled" value="false" />
    <add key="PreserveLoginUrl" value="false" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
    <add key="ProductFamilyId" value="19" />
    <add key="ProductCategoryId" value="5" />
    <add key="ProductBrandId" value="1" />
    <add key="PrintTemplateId" value="0" />
    <add key="SerialRequired" value="false" />
    <add key="VatCodeId" value="0" />
    <add key="ValidityPeriod" value="S" />
    <add key="RefundTypeId " value="0" />
    <add key="PrintCoupon " value="true" />
    <add key="MinPriority" value="1" />
    <add key="MaxPriority" value="12" />
    <!--Key for deloyment type e.g. dev and live -->
    <add key="DeploymentMode" value="dev" />
    <!--Keys for SmartApi service-->
    <add key="SalesChannel" value="Web" />
    <add key="AgentCode" value="007" />
    <add key="PartnerCode" value="NX" />
    <add key="CampaignCode" value="DEFAULT" />
    <add key="UserId" value="userid" />
    <add key="SmartApiUsername" value="SMART" />
    <add key="SmartApiPassword" value="smart" />
  </appSettings>
  <nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" throwExceptions="true" internalLogFile="c:\nlog.txt">

    <!-- make sure to set 'Copy To Output Directory' option for this file -->
    <!-- go to http://nlog-project.org/wiki/Configuration_file for more information -->

    <targets>
      <target xsi:type="Database" name="DMSLogger" connectionString="Data Source=ukpdpmc3;Initial Catalog=PartnersDB;Integrated Security=True" dbDatabase="PartnersDB">
        <commandText>INSERT INTO DMSLog([LogLevel], [Message], [Exception], [createDate]) VALUES (@logLevel, @message, @exception, @createDate)</commandText>
        <parameter name="@createDate" layout="${date:format=yyyy-MM-dd HH\:mm\:ss.fff}" />
        <parameter name="@logLevel" layout="${level}" />
        <parameter name="@message" layout="${message}" />
        <parameter name="@exception" layout="${exception:format=Message,StackTrace}" />

        <dbProvider>System.Data.SqlClient</dbProvider>
        <connectionString>Data Source=ukpdpmc3;Initial Catalog=DMS;Integrated Security=True</connectionString>
      </target>
    </targets>

    <rules>
      <logger name="*" minlevel="Info" writeTo="DMSLogger"></logger>
    </rules>
  </nlog>
  <system.web>
    <customErrors mode="Off" defaultRedirect="~/Views/Shared/Error.cshtml">
      <error redirect="~/Error/Index" statusCode="404" />
    </customErrors>
    <compilation debug="true" targetFramework="4.0" />
    <!--<authentication mode="Windows">
      --><!--<forms name=".ADAuthCookie" loginUrl="~/Account/Login" timeout="2880" />--><!--
    </authentication>
    <authorization>
      <deny users="?" />
    </authorization>-->
    <!--<membership defaultProvider="ActiveDirectoryMembershipProvider">
      <providers>
        <add name="ActiveDirectoryMembershipProvider" type="System.Web.Security.ActiveDirectoryMembershipProvider, System.Web,          Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" applicationName="FormsWithADAuth" connectionStringName="ADConnectionString" attributeMapUsername="sAMAccountName" />
      </providers>
    </membership>-->
    <identity impersonate="true" />
    <pages>
      <namespaces>
        <add namespace="System.Web.Helpers" />
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Optimization" />
        <add namespace="System.Web.Routing" />
        <add namespace="System.Web.WebPages" />
      </namespaces>
    </pages>

    <!-- Glimpse: This can be commented in to add additional data to the Trace tab when using WebForms
        <trace writeToDiagnosticsTrace="true" enabled="true" pageOutput="false"/> -->
    <httpModules>
      <add name="Glimpse" type="Glimpse.AspNet.HttpModule, Glimpse.AspNet" />
    </httpModules>
    <httpHandlers>
      <add path="glimpse.axd" verb="GET" type="Glimpse.AspNet.HttpHandler, Glimpse.AspNet" />
    </httpHandlers>
  </system.web>
  <system.webServer>

    <modules runAllManagedModulesForAllRequests="true">

      <add name="Glimpse" type="Glimpse.AspNet.HttpModule, Glimpse.AspNet" preCondition="integratedMode" />
    </modules>
    <handlers>
      <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
      <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
      <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
      <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
      <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
      <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />

      <add name="Glimpse" path="glimpse.axd" verb="GET" type="Glimpse.AspNet.HttpHandler, Glimpse.AspNet" preCondition="integratedMode" />
    </handlers>

    <validation validateIntegratedModeConfiguration="false" />
  </system.webServer>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v11.0" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.Odbc" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>

  <glimpse defaultRuntimePolicy="On" endpointBaseUri="~/Glimpse.axd">
  <runtimePolicies>
        <ignoredTypes>
        <add type="Glimpse.AspNet.Policy.LocalPolicy, Glimpse.AspNet" />
        </ignoredTypes>
  </runtimePolicies>
  </glimpse>
</configuration>
c# asp.net-mvc entity-framework
1个回答
0
投票

遇到了完全相同的问题,我的最初工作正常,然后因相同的错误而停止工作。甚至尝试卸载并重新安装.NET桌面开发和数据存储和处理,但仍然不起作用。我所做的是在“工具”菜单上选择导入和导出设置,然后(因为我使用的是 c# )将 C# 设置覆盖回默认值。关闭并重新打开 Visual Studio,尝试运行添加基于服务的数据库,它再次工作并将本地 mdf 数据库添加到我的解决方案中。希望这可以帮助!托尼

© www.soinside.com 2019 - 2024. All rights reserved.