简体   繁体   English

即使已更改,实体框架仍尝试连接到旧的ADO.NET提供程序

[英]Entity Framework keeps trying to connect to old ADO.NET provider eventhough it has been changed

I changed a MySQL project's DB connection to target SQL Server from MySQL. 我将MySQL项目的数据库连接更改为从MySQL定位到SQL Server。 However, when trying to run Update-Database -StartProjectName ProjectName targeting a database in SQL Server, I receive the following error 但是,当尝试运行针对SQL Server中的数据库的Update-Database -StartProjectName ProjectName ,出现以下错误

Schema specified is not valid. 指定的架构无效。 Errors: (0,0) : error 0152: No Entity Framework provider found for the ADO.NET provider with invariant name 'MySql.Data.MySqlClient'. 错误:(0,0):错误0152:未找到具有不变名称'MySql.Data.MySqlClient'的ADO.NET提供程序的实体框架提供程序。 Make sure the provider is registered in the 'entityFramework' section of the application config file. 确保提供程序已在应用程序配置文件的“ entityFramework”部分中注册。 See http://go.microsoft.com/fwlink/?LinkId=260882 for more information. 有关更多信息,请参见http://go.microsoft.com/fwlink/?LinkId=260882

So I tried to ensure that my project was free of MySQL 所以我试图确保我的项目没有MySQL

  1. Use ctrl+F and search for all MySQL keyword : Found none. 使用ctrl + F并搜索所有MySQL关键字:找不到任何关键字。
  2. Uninstall MySQL packages via NuGET package manager 通过NuGET软件包管理器卸载MySQL软件包

Why does Entity Framework keep asking me for MySQL provider when I have clearly indicated that it should use the default MS SQL provider in the config file? 当我明确指出它应该在配置文件中使用默认的MS SQL提供程序时,为什么Entity Framework一直问我MySQL提供程序?

This is my config file: 这是我的配置文件:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <connectionStrings>
   <add name="Connection" connectionString="Data Source=SQLSERVER123;Database=DB123;Integrated Security=true" providerName="System.Data.SqlClient" />
  </connectionStrings>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="mssqllocaldb" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
</configuration>

This is my DbContext file: 这是我的DbContext文件:

using System;
using System.Data.Entity;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;

namespace ProjectName.MSSQL
{
    public class ProjectNameContext:DbContext
    {
        public ProjectNameContext()
            : base("Connection")
        {

        }

        public static ProjectNameContext Create()
        {
            return new ProjectNameContext();
        }

        public DbSet<Users> Users { get; set; }
    }
}

So what worked for me was I created my own DbConfiguration class and referenced it using the codeConfigurationType property in App.config 所以对我DbConfiguration我创建了自己的DbConfiguration类,并使用App.config的codeConfigurationType属性对其进行了引用

My custom Dbconfiguration class 我的自定义Dbconfiguration

using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Data.Entity.SqlServer;

namespace ProjectName.MSSQL
{
    public class MSSQLDbConfiguration:DbConfiguration
    {
        public MSSQLDbConfiguration()
        {
            this.SetProviderServices("System.Data.SqlClient", System.Data.Entity.SqlServer.SqlProviderServices.Instance);
            this.SetDefaultConnectionFactory(new LocalDbConnectionFactory("v11.0"));
        }
    }
}

My App.config 我的App.config

<entityFramework codeConfigurationType="ProjectName.MSSQL.MSSQLDbConfiguration, ProjectName.MSSQL">
...
any stuff...
...
</entityFramework>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 找不到ADO.NET提供程序的实体框架提供程序 - No Entity Framework provider found for the ADO.NET provider 通用实体框架项目“没有为ADO.NET提供者找到实体框架提供者” - Common Entity Framework Project “No Entity Framework provider found for the ADO.NET provider” 没有为ADO.NET提供程序找到具有不变名称“System.Data.SqlClient”的实体框架提供程序。 - No Entity Framework provider found for the ADO.NET provider with invariant name 'System.Data.SqlClient'. 错误:找不到具有不变名称'System.Data.SqlClient'的ADO.NET提供程序的实体框架提供程序 - Error: No Entity Framework provider found for the ADO.NET provider with invariant name 'System.Data.SqlClient' 找不到具有不变名称“Oracle.ManagedDataAccess.Client”的ADO.NET提供程序的实体框架提供程序 - No Entity Framework provider found for the ADO.NET provider with invariant name 'Oracle.ManagedDataAccess.Client' 未找到具有不变名称&#39;MySql.Data.MySqlClient&#39;的ADO.NET提供程序的实体框架提供程序-WCF - No Entity Framework provider found for the ADO.NET provider with invariant name 'MySql.Data.MySqlClient' - WCF 从ADO.NET迁移到实体框架 - Migrate from ADO.NET to Entity Framework LinqToSql和实体框架还是ADO.Net? - LinqToSql and Entity Framework or ADO.Net? 使用ADO.NET实体框架时出错 - Error Using ADO.NET Entity Framework ADO.Net实体框架事务 - ADO.Net Entity Framework Transactions
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM