Oracle.ManagedDataAccess.EntityFramework - ORA-0

2019-05-12 04:03发布

我想implemente代码首先迁移与Oracle.ManagedDataAccess 6.121.1.0提供商,但没有成功可言。

正如我收到一个ORA-代码,我假设连接被成功打开。 但是,迁移的失败,因为,也许,供应商被表现为一个SQL Server,而不是甲骨文。 我认为,东阳它装盘使用“DBO”作为默认模式。

这里是我的web.config设置:

<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="Oracle.ManagedDataAccess.Client"
             type="OracleInternal.Common.ODPMSectionHandler, Oracle.ManagedDataAccess, Version=4.121.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />
  </configSections>
  <entityFramework>
    <contexts>
      <context type="MyProject.Context.MainContext, MyProject.Context">
        <databaseInitializer type="MyProject.Context.Config.ContextInitializer, MyProject.Context" />
      </context>
    </contexts>
    <defaultConnectionFactory type="Oracle.ManagedDataAccess.Client.OracleClientFactory, Oracle.ManagedDataAccess" />    
    <providers>    
      <provider invariantName="Oracle.ManagedDataAccess.Client" 
                type="Oracle.ManagedDataAccess.EntityFramework.EFOracleProviderServices, Oracle.ManagedDataAccess.EntityFramework, Version=6.121.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />
    </providers>
  </entityFramework>
  <system.data>
    <DbProviderFactories>
      <remove invariant="Oracle.ManagedDataAccess.Client" />
      <add name="ODP.NET, Managed Driver"
           invariant="Oracle.ManagedDataAccess.Client"
           description="Oracle Data Provider for .NET, Managed Driver"
           type="Oracle.ManagedDataAccess.Client.OracleClientFactory, Oracle.ManagedDataAccess, Version=4.121.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />
    </DbProviderFactories>
  </system.data>
  <connectionStrings>
    <add name="MainContext"
         providerName="Oracle.ManagedDataAccess.Client"
         connectionString="Data Source=OracleServer:1521/BRSYSDS;User ID=USER;Password=PASSWORD;" />
  </connectionStrings>
  <!-- other settings -->
</configuration>

这里的堆栈跟踪:

[OracleException(0x77e):ORA-01918:用户 'DBO' 不存在]
OracleInternal.ServiceObjects.OracleCommandImpl.VerifyExecution(OracleConnectionImpl connectionImpl,的Int32&cursorId,布尔bThrowArrayBindRelatedErrors,OracleException&exceptionForArrayBindDML,布尔逻辑hasMoreRowsInDB,布尔bFirstIterationDone)652 OracleInternal.ServiceObjects.OracleCommandImpl.VerifyExecution(OracleConnectionImpl connectionImpl,的Int32&cursorId,布尔bThrowArrayBindRelatedErrors,OracleException&exceptionForArrayBindDML,布尔bFirstIterationDone )+39
OracleInternal.ServiceObjects.OracleCommandImpl.ExecuteNonQuery(字符串的CommandText,OracleParameterCollection paramColl,的CommandType命令类型,OracleConnectionImpl connectionImpl,的Int32 longFetchSize,Int64的clientInitialLOBFS,OracleDependencyImpl orclDependencyImpl,Int64的[]&scnFromExecution,OracleParameterCollection&bindByPositionParamColl,布尔逻辑bBindParamPresent,OracleException&exceptionForArrayBindDML,布尔isFromEF)7480
Oracle.ManagedDataAccess.Client.OracleCommand.ExecuteNonQuery()+678
System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.b__0(的DbCommand吨,DbCommandInterceptionContext 1 c) +10
System.Data.Entity.Infrastructure.Interception.InternalDispatcher
1 c) +10
System.Data.Entity.Infrastructure.Interception.InternalDispatcher
1 c) +10
System.Data.Entity.Infrastructure.Interception.InternalDispatcher
1.Dispatch(t目标靶,Func键3 operation, TInterceptionContext interceptionContext, Action 3执行,动作3 executed) +72
System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.NonQuery(DbCommand command, DbCommandInterceptionContext interceptionContext) +357
System.Data.Entity.Internal.InterceptableDbCommand.ExecuteNonQuery() +104
System.Data.Entity.Migrations.DbMigrator.ExecuteSql(DbTransaction transaction, MigrationStatement migrationStatement, DbInterceptionContext interceptionContext) +152
System.Data.Entity.Migrations.DbMigrator.ExecuteStatementsInternal(IEnumerable
3 executed) +72
System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.NonQuery(DbCommand command, DbCommandInterceptionContext interceptionContext) +357
System.Data.Entity.Internal.InterceptableDbCommand.ExecuteNonQuery() +104
System.Data.Entity.Migrations.DbMigrator.ExecuteSql(DbTransaction transaction, MigrationStatement migrationStatement, DbInterceptionContext interceptionContext) +152
System.Data.Entity.Migrations.DbMigrator.ExecuteStatementsInternal(IEnumerable
3 executed) +72
System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.NonQuery(DbCommand command, DbCommandInterceptionContext interceptionContext) +357
System.Data.Entity.Internal.InterceptableDbCommand.ExecuteNonQuery() +104
System.Data.Entity.Migrations.DbMigrator.ExecuteSql(DbTransaction transaction, MigrationStatement migrationStatement, DbInterceptionContext interceptionContext) +152
System.Data.Entity.Migrations.DbMigrator.ExecuteStatementsInternal(IEnumerable
1个migrationStatements,DbTransaction交易,DbInterceptionContext interceptionContext)82
System.Data.Entity.Migrations.DbMigrator.ExecuteStatementsInternal(IEnumerable的1 migrationStatements, DbConnection connection) +626
System.Data.Entity.Migrations.<>c__DisplayClass30.<ExecuteStatements>b__2e() +19
System.Data.Entity.Infrastructure.DefaultExecutionStrategy.Execute(Action operation) +9
System.Data.Entity.Migrations.DbMigrator.ExecuteStatements(IEnumerable
1 migrationStatements, DbConnection connection) +626
System.Data.Entity.Migrations.<>c__DisplayClass30.<ExecuteStatements>b__2e() +19
System.Data.Entity.Infrastructure.DefaultExecutionStrategy.Execute(Action operation) +9
System.Data.Entity.Migrations.DbMigrator.ExecuteStatements(IEnumerable
1 migrationStatements, DbConnection connection) +626
System.Data.Entity.Migrations.<>c__DisplayClass30.<ExecuteStatements>b__2e() +19
System.Data.Entity.Infrastructure.DefaultExecutionStrategy.Execute(Action operation) +9
System.Data.Entity.Migrations.DbMigrator.ExecuteStatements(IEnumerable
1个migrationStatements,DbTransaction existingTransaction)194
System.Data.Entity.Migrations.DbMigrator.ExecuteStatements(IEnumerable的1 migrationStatements) +7
System.Data.Entity.Migrations.DbMigrator.ExecuteOperations(String migrationId, XDocument targetModel, IEnumerable
1 migrationStatements) +7
System.Data.Entity.Migrations.DbMigrator.ExecuteOperations(String migrationId, XDocument targetModel, IEnumerable
1 migrationStatements) +7
System.Data.Entity.Migrations.DbMigrator.ExecuteOperations(String migrationId, XDocument targetModel, IEnumerable
1个操作,IEnumerable的1 systemOperations, Boolean downgrading, Boolean auto) +825
System.Data.Entity.Migrations.DbMigrator.AutoMigrate(String migrationId, VersionedModel sourceModel, VersionedModel targetModel, Boolean downgrading) +564
System.Data.Entity.Migrations.DbMigrator.Upgrade(IEnumerable
1 systemOperations, Boolean downgrading, Boolean auto) +825
System.Data.Entity.Migrations.DbMigrator.AutoMigrate(String migrationId, VersionedModel sourceModel, VersionedModel targetModel, Boolean downgrading) +564
System.Data.Entity.Migrations.DbMigrator.Upgrade(IEnumerable
1 systemOperations, Boolean downgrading, Boolean auto) +825
System.Data.Entity.Migrations.DbMigrator.AutoMigrate(String migrationId, VersionedModel sourceModel, VersionedModel targetModel, Boolean downgrading) +564
System.Data.Entity.Migrations.DbMigrator.Upgrade(IEnumerable
1个pendingMigrations,字符串targetMigrationId,字符串lastMigrationId)404
System.Data.Entity.Migrations.DbMigrator.UpdateInternal(字符串targetMigration)447
System.Data.Entity.Migrations。<> c__DisplayClassc.b__b()13
System.Data.Entity.Migrations.DbMigrator.EnsureDatabaseExists(动作mustSucceedToKeepDatabase)422
System.Data.Entity.Migrations.DbMigrator.Update(字符串targetMigration)+78
System.Data.Entity.Internal.DatabaseCreator.CreateDatabase(InternalContext internalContext,Func键3 createMigrator, ObjectContext objectContext) +89
System.Data.Entity.Internal.InternalContext.CreateDatabase(ObjectContext objectContext, DatabaseExistenceState existenceState) +116
System.Data.Entity.Database.Create(DatabaseExistenceState existenceState) +218
System.Data.Entity.DropCreateDatabaseAlways
3 createMigrator, ObjectContext objectContext) +89
System.Data.Entity.Internal.InternalContext.CreateDatabase(ObjectContext objectContext, DatabaseExistenceState existenceState) +116
System.Data.Entity.Database.Create(DatabaseExistenceState existenceState) +218
System.Data.Entity.DropCreateDatabaseAlways
3 createMigrator, ObjectContext objectContext) +89
System.Data.Entity.Internal.InternalContext.CreateDatabase(ObjectContext objectContext, DatabaseExistenceState existenceState) +116
System.Data.Entity.Database.Create(DatabaseExistenceState existenceState) +218
System.Data.Entity.DropCreateDatabaseAlways
1.InitializeDatabase(TContext上下文)137

Answer 1:

我有同样的问题,它是由蒂亚戈·卢纳尔迪的响应解决。 谢谢。 我没有足够的信誉来投票你的答复。 更何况在这里,我以大写字母设置我的架构名称后取得了成功。

将这个在上下文文件中新的DbContext类下,像这样的:

public partial class MyAppContext : DbContext
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
    modelBuilder.HasDefaultSchema("UPPERCASE_SCHEMA_NAME");
...


Answer 2:

我解决这个问题只需设置默认的模式在模型构建器

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
    modelBuilder.HasDefaultSchema("MyOracleSchema");

    // ...
}


Answer 3:

设置默认模式并没有为我工作。 我发现通过自定义的迁移历史表设置不同的架构解决方案。

你可以在这里找到一个解决方案: LINK 。



Answer 4:

用户也DBO进来缺少表的完全限定名称的情况下。 这可能不会映射到数据库中的右表。



Answer 5:

如果您使用的自动迁移(因为我),然后记: modelBuilder.HasDefaultSchema whouldn't帮助,直到您切换到明确的迁移。

从甲骨文文件 :

代码优先自动迁移仅限于只dbo架构工作。 由于这个限制,建议使用基于代码的迁移,即通过添加迁移命令添加明确的迁移


Answer 6:

在代码首先,你可以使用DataAnnotations的表。

[表( “Emplpoyee”,模式= “您的模式名”]



文章来源: Oracle.ManagedDataAccess.EntityFramework - ORA-01918: user 'dbo' does not exist