Multi DbContext MSSQL & MySQL
See original GitHub issueI try to use 2 db connection 1 to MSSQL (abp-zero [roles,users,etc]) one to business data on MySQL.
I use the sample code from https://github.com/aspnetboilerplate/aspnetboilerplate-samples/tree/master/MultipleDbContextDemo and I create the table and it’s work when I call a method, based on a AbpModule to need data from MySql i catch an excection
System.Data.Entity.Core.EntityCommandExecutionException: An error occurred while executing the command definition. See the inner exception for details. ---> System.Data.SqlClient.SqlException: Invalid object name 'mdm.app_fd_tb_company'. in System.Data.SqlClient.SqlCommand.<>c.<ExecuteDbDataReaderAsync>b__167_0(Task
1 result)
in System.Threading.Tasks.ContinuationResultTaskFromResultTask2.InnerInvoke() in System.Threading.Tasks.Task.Execute()
So the excetion is relate to System.Data.SqlClient and not to MySql. How can tell to ABP that need to use EF for MySql and not to SQL server.
Another operation that I need to do is to set the initializer
Database.SetInitializer<mySqlDbContext>(null);
If I not set this row code first say me the database are not update
my db context refered to mysql is declared in this way
[DbConfigurationType(typeof(MySqlEFConfiguration))] public class mySqlDbContext : AbpDbContext {
Issue Analytics
- State:
- Created 7 years ago
- Comments:6 (2 by maintainers)
Top GitHub Comments
First of all many thanks to @hikalkan.
In order to use multi connection:
public secondDbContext(string nameOrConnectionString) : base(nameOrConnectionString) { }
in according to https://github.com/aspnetboilerplate/aspnetboilerplate-templates/blob/master/src/AbpCompanyName.AbpProjectName.EntityFramework/EntityFramework/AbpProjectNameDbContext.csAnd after this modification my solution work wy MSSQL and MySQL.
mat
ok I send it full configuration.
So after a lot of investigation i found the problem(probably) but not the solution.
In EF module I set
Configuration.DefaultNameOrConnectionString = "mySql"; // "Default"
So the
public class EntityFrameworkConventionalRegistrar : IConventionalDependencyRegistrar
use connection name to register by IoC.I try to use ` Database.SetInitializer<mysqlDbContext>(new aa()); } }
` In Debug I see the the connection is not MySql but MSSQL but the provider is correctly regitered. I have try the custom repository.
I study your multi connection example and I see that is works in same db instance it’s only a separate database.
To solve my issue I think to need extend AbpModule and AbpEF. in EF need to possibile define a local connection string to allow a rigistration for each module with specific connection.