entity-framework - Entity Framework 6 Code First 迁移不适用于 Oracle 数据库
问题描述
我正在使用 EF6 和 Oracle 数据库开发 ASP.NET MVC 5 应用程序。
我正在使用代码 First 方法,我创建了我的实体和 My Context 类,然后我尝试了Enable and Add a Migration
但我得到了这个错误。
但是,如果我使用 SQL SERVER 代替 Oracle 数据库,它可以正常工作,但不适用于 Oracle 数据库。
这是错误:
System.Data.Entity.Core.ProviderIncompatibleException: An error occurred accessing the database. This usually means that the connection to the database failed. Check that the connection string is correct and that the appropriate
DbContext 构造函数用于指定它或在应用程序的配置文件中找到它。请参阅http://go.microsoft.com/fwlink/?LinkId=386386有关 DbContext 和连接的信息。有关失败的详细信息,请参阅内部异常。---> System.Data.Entity.Core.ProviderIncompatibleException:提供者没有返回 ProviderManifestToken 字符串。---> Oracle.ManagedDataAccess.Client.OracleException: ORA-12154: TNS : 不可能的 de résoudre l'identificateur de connexion indiqué ---> OracleInternal.Network.NetworkException: ORA-12154: TNS : 不可能的 de résoudre l'identificateur de在 OracleInternal.Network.OracleCommunication.DoConnect(String tnsDescriptor) 在 OracleInternal.Network.OracleCommunication.Connect(String tnsDescriptor, Boolean doNAHandshake, String IName) 在 OracleInternal. .ServiceObjects。
3.Get(ConnectionString csWithDiffOrNewPwd, Boolean bGetForApp, OracleConnection connRefForCriteria, String affinityInstanceName, Boolean bForceMatch) at OracleInternal.ConnectionPool.OraclePoolManager.Get(ConnectionString csWithNewPassword, Boolean bGetForApp, OracleConnection connRefForCriteria, String affinityInstanceName, Boolean bForceMatch) at OracleInternal.ConnectionPool.OracleConnectionDispenser
3.Get(ConnectionString cs, PM conPM, ConnectionString pmCS, SecureString securePassword, SecureString secureProxyPassword, OracleConnection connRefForCriteria) 在 Oracle.ManagedDataAccess.Client.OracleConnection.Open() 在 Oracle.ManagedDataAccess.EntityFramework.EFOracleProviderServices.GetDbProviderManifestToken(DbConnection connection) 在系统.Data.Entity.Core.Common.DbProviderServices.GetProviderManifestToken(DbConnection connection) --- 内部异常堆栈跟踪结束 --- System.Data.Entity.Core.Common.DbProviderServices.GetProviderManifestToken(DbConnection connection) 在 System.Data .Entity.Utilities.DbProviderServicesExtensions.GetProviderManifestTokenChecked(DbProviderServices providerServices,DbConnection 连接)--- 内部异常堆栈跟踪结束 --- 在 System.Data.Entity.Utilities.DbProviderServicesExtensions.GetProviderManifestTokenChecked(DbProviderServices providerServices, DbConnection connection) 在 System.Data.Entity.Infrastructure.DefaultManifestTokenResolver.<>c__DisplayClass1.b__0 (元组3 k) at System.Collections.Concurrent.ConcurrentDictionary
2.GetOrAdd(TKey key, Func2 valueFactory) at System.Data.Entity.Infrastructure.DefaultManifestTokenResolver.ResolveManifestToken(DbConnection connection) at System.Data.Entity.Utilities.DbConnectionExtensions.GetProviderInfo(DbConnection connection, DbProviderManifest& providerManifest) at System.Data.Entity.DbModelBuilder.Build(DbConnection providerConnection) at System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext) at System.Data.Entity.Internal.RetryLazy
System.Data.Entity.Migrations.Design.MigrationScaffolder 的 ctor(DbMigrationsConfiguration 配置) System.Data.Entity.Migrations.Design.ToolingFacade.ScaffoldRunner.RunCore() 的 System.Data.Entity.Migrations 的ctor(DbMigrationsConfiguration migrationsConfiguration) .Design.ToolingFacade.BaseRunner.Run() 访问数据库时出错。这通常意味着与数据库的连接失败。检查连接字符串是否正确,以及是否使用了适当的 DbContext 构造函数来指定它或在应用程序的配置文件中找到它。看 System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.Run() 处的 ScaffoldRunner.RunCore() 访问数据库时出错。这通常意味着与数据库的连接失败。检查连接字符串是否正确,以及是否使用了适当的 DbContext 构造函数来指定它或在应用程序的配置文件中找到它。看 System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.Run() 处的 ScaffoldRunner.RunCore() 访问数据库时出错。这通常意味着与数据库的连接失败。检查连接字符串是否正确,以及是否使用了适当的 DbContext 构造函数来指定它或在应用程序的配置文件中找到它。看http://go.microsoft.com/fwlink/?LinkId=386386了解有关 DbContext 和连接的信息。有关失败的详细信息,请参阅内部异常*。
这是我的连接字符串:
<connectionStrings>
<add name="BiatContext" providerName="Oracle.ManagedDataAccess.Client" connectionString="User Id=SYSTEM;Password=admin;Data Source=oracle" />
</connectionStrings>
解决方案
您必须像这样更改连接字符串
<connectionStrings>
<add name="BiatContext" providerName="Oracle.ManagedDataAccess.Client" connectionString="User Id=SYSTEM;Password=admin; Min Pool Size=20; Max Pool Size=200; Connection Lifetime=120;Connection Timeout=70;Incr Pool Size=2; Decr Pool Size=3;Data Source=oracle" />
</connectionStrings>
推荐阅读
- drupal-8 - D8 - 我需要在我的街区使用许多服务,这段代码对吗?
- javascript - 从父节点中删除子节点
- python-2.7 - Apache Beam 在 Google Dataflow 工作器上的“process_outputs”期间出现令人困惑的错误
- git - Git 没有从 master 看到我的分支,如何取回它?
- openshift - 带有运行 Java > 8 的图像的 fabric8 maven 插件配置
- python - 使用 Python 编辑大型 Excel 文件
- json - Angular - 将json文件分配给类的问题
- botframework - Microsoft BotBuilder Azure OAuth 身份验证 ConnectionSettingName 值
- javascript - 为数据库构建 Web 界面
- python - AttributeError:“dict”对象没有属性“is_active”(PyMongo 和 Flask)