0

I created a software that is database independent with code first entity framework

every models can work on mysq, mssql,oracle etc.

program decide automaticaly connection string while starting.

mssql and mysql were working well befor i add oracle. now i added oracle in config file.after that oracle and mysql are working well mysql return error.

My error is "An unhandled exception of type 'System.ArgumentException' occurred in Oracle.ManagedDataAccess.dll

Additional information: 'server' is an invalid connection string attribute"

as you see error message mssqlcontext try to use or checking rules of oracle configurations. how can i define mssql configuration Without disrupting oracle or how can i define oracleconfiguration Without disrupting mssql this is my app.config

<?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"/>
    <section name="oracle.manageddataaccess.client"
      type="OracleInternal.Common.ODPMSectionHandler, Oracle.ManagedDataAccess, Version=4.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342"/>
  </configSections>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
  </startup>
  <entityFramework>
    <providers>
      <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6"/>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer"/>
      <provider invariantName="Oracle.ManagedDataAccess.Client"
        type="Oracle.ManagedDataAccess.EntityFramework.EFOracleProviderServices, Oracle.ManagedDataAccess.EntityFramework, Version=6.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342"/>
    </providers>
  </entityFramework>

  <system.data>
    <DbProviderFactories>
      <remove invariant="MySql.Data.MySqlClient"/>
      <add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL"
        type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.9.9.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"/>
      <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.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342"/>



    </DbProviderFactories>

  </system.data>

  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <publisherPolicy apply="no"/>
        <assemblyIdentity name="Oracle.ManagedDataAccess" publicKeyToken="89b483f429c47342" culture="neutral"/>
        <bindingRedirect oldVersion="4.121.0.0 - 4.65535.65535.65535" newVersion="4.121.2.0"/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

</configuration>

this was my app.config before i add oracle

<?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>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>

  <entityFramework>
    <providers>
      <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6"  />
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>

  <system.data>
    <DbProviderFactories>
      <remove invariant="MySql.Data.MySqlClient" />
      <add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.9.9.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
    </DbProviderFactories>

  </system.data>
</configuration>

edit 1

 public  class MSSQLDBContext : BaseDbContext, IDbContext
    {
       //yeni
        public MSSQLDBContext() : base(GlobalData.ConnStringMSSQLMigrationSysncDatabase) {

        }
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Brand>().Property(c => c.deneme2).HasColumnType("xml");
            base.OnModelCreating(modelBuilder);
        }
    }

[DbConfigurationType(typeof(MySqlEFConfiguration))]
    public class MySQLDbContext : BaseDbContext, IDbContext
    {
        public MySQLDbContext():base(GlobalData.ConnStringMySQLMigrationSysncDatabase){}
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Brand>().Property(c => c.deneme2).HasColumnType("LONGTEXT");
            base.OnModelCreating(modelBuilder);
        }
    }

 public class OracleDbContext: BaseDbContext, IDbContext
    {
       public OracleDbContext() : base(GlobalData.ConnStringORACLEMigrationSyncDatabase) { }




       protected override void OnModelCreating(System.Data.Entity.DbModelBuilder modelBuilder)
       {
           modelBuilder.HasDefaultSchema("SEMIH");
           base.OnModelCreating(modelBuilder);

       }
    }
  • The exception message indicates **connection string** error, so you might need to look at your `` section (not shown in the post). – Ivan Stoev Jan 04 '17 at 11:43
  • Ivan Thanx for your message, i tested connection string its working. public MSSQLDBContext() : base(GlobalData.ConnStringMSSQLMigrationSysncDatabase) { } after i add oracle to my project, this connection string started to say "'server' is an invalid connection string attribute" error come from Oracle.ManagedDataAccess.dll. i think mssql db context cannot take its configuration type ? – Semih YILDIZ Jan 04 '17 at 12:00
  • Look at you connection string for Oracle. Looks like it contains something like "server=..." inside which is unsupported by ODP.NET. You have to use different connection strings for different databases, correct? – Ivan Stoev Jan 04 '17 at 12:02
  • yes i use different connection string for different database, every database has own dbcontext these inherited from baseDbContext, Now oracle and mysql working well – Semih YILDIZ Jan 04 '17 at 12:05

1 Answers1

0

for mssqldbcontex i defined new dbConfiguration that inhereted from DbConfiguration class and i set its provider factory

public class mssqlConfiguration : DbConfiguration
    {
        public mssqlConfiguration()
        {
             SetProviderFactory("System.Data.SqlClient", System.Data.SqlClient.SqlClientFactory.Instance);

        }
    }

and i create new class for oracleDbcontex like mssqlDbContex

public class OracleProviderConfig : DbConfiguration
   {
       public OracleProviderConfig()
       {

           SetProviderServices("Oracle.ManagedDataAccess.Client", EFOracleProviderServices.Instance);
           SetProviderFactory("Oracle.ManagedDataAccess.Client", OracleClientFactory.Instance);

       }
   }

and i called this configuration on top of their dbContext like this

[DbConfigurationType(typeof(OracleProviderConfig))]
   public class OracleDbContext: BaseDbContext, IDbContext

at last i have clear providers from my app.config

<?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"/>
    <section name="oracle.manageddataaccess.client"
      type="OracleInternal.Common.ODPMSectionHandler, Oracle.ManagedDataAccess, Version=4.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342"/>
  </configSections>
  <entityFramework>
    <providers>

    </providers>
  </entityFramework>
<system.data>

  </system.data>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<publisherPolicy apply="no"/>
<assemblyIdentity name="Oracle.ManagedDataAccess" publicKeyToken="89b483f429c47342" culture="neutral"/>
<bindingRedirect oldVersion="4.121.0.0 - 4.65535.65535.65535" newVersion="4.121.2.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>

</configuration>

it solved