c# - 无法确定类型为“System.Data.SqlClient.SqlConnection”的连接的 DbProviderFactory 类型
问题描述
我有使用 EF 6.0 开发的 Asp.net MVC 应用程序。
当我从源代码运行它时,它工作得很好。但是当我在 Windows server 2016 机器上部署应用程序时,它会在页面上显示以下消息。
错误:从数据库获取提供者信息时出错。这可能是由 Entity Framework 使用不正确的连接字符串引起的。检查内部异常以获取详细信息并确保连接字符串正确。:无法确定类型为“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>
解决方案
推荐阅读
- python - 如何将 GitHub 制作成 pandas DataFrame?
- typescript - 如何创建数字的子类型?
- python - 将字符串中的最后一个单词与前面的每个单词组合起来
- swift - 使用通用参数创建 async/await 函数
- python - 如何使用 pd.read_xml 正确解析 SEC cal.xml 文件?
- css - Safari 和 Chrome 之间的 CSS 'visibility:collapse' 错误?
- c# - 如何在 Unity 中使 UI 看起来像 Pixel Perfect?
- java - 使用的 lambda 表达式中未触发断点 n CompletableFuture.supplyAsync(Supplier) (不是由于延迟执行)
- c# - 下拉值需要传入repeater控件绑定方法
- android - 获取 Android Dialog Window 的实际偏移量