Base solution for your next web application
Ends in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Read data from another Database - Custom Repository #1806


User avatar
0
sregitz created

New to this framework.

Have tried working through examples but once I ran solution my new repository was created using the Default ContextDB (ABP Db) instead of the one I want to read from.

Are there any examples of using this framework to simply interact with other data sources (databases) on the same SQL Server?


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

    Hi,

    You can take a look at MultipleDbContextDemo sample here <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate-samples/tree/master/MultipleDbContextDemo">https://github.com/aspnetboilerplate/as ... ontextDemo</a>

    What you are looking for is implemented here. Please let us know if you have any problems while implementing it.

  • User Avatar
    0
    sregitz created

    You are correct. I found this over the weekend and figured out what was wrong with my solution. When creating my 'second' DbContext class I copied the first one. I want to post this here so anyone else with this issue can find a solution. What I had to do was remove the constructor for passing the connection string from the PreInitialize method : public MyAppDbContext(string nameOrConnectionString) : base(nameOrConnectionString)

    as well as delete the constructor used by ABP to pass a Test/Mock connection string: public MyAppDbContext(DbConnection dbConnection) : base(dbConnection, true)

    although I believe I probably could leave the latter.

    The first one (used by PreInitialize) was the culprit. I looked inside the implementation for MultipleDbContextDemo and discovered that nuance.

    Thank you for your time / response.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Thanks for sharing your experience :)