Base solution for your next web application
Open Closed

How to connect multiple databases in .NETCore using Dapper to import data in existing entities? #8743


User avatar
0
ISTeam created

I am using ASP.NET Core MVC and jQuery template.

In the master database all Abp tables are there as default. I have added three entities/tables to show in UI.

Using background worker I need to fill the data in those three tables from three different databases of three CRMs, which are neither Abp style nor I have designed the db context. For that I have added three additional connection strings in the appsettings.json file. Downloaded dapper package in X.Dashboard.Core project where my background worker classes to be designed.

Two of the databases are MSSQL and one is MySQL. I have created SQL query on how to select the data from each of them.

How can I connect to those databases from the workers to fire 'SELECT' query using Dapper and then I would insert in my application database.

Should I just go with old way which requires to download nuget package - System.Data.SqlClient like below:

using (SqlConnection db = new SqlConnection(CRM_DbConnectionString))
{
    db.Open();
    Orders = db.Query<Order>(Query_file_content).ToList();
    db.Close();
}

Or is there a better approach in .NET Core 3.1 latest template of ANZ?

Please advise. Thanks.


1 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @ISTeam

    It is better to use the code you have shared for this case.