question

MikaelaCaron-2451 avatar image
0 Votes"
MikaelaCaron-2451 asked ·

Multiple Data Sources Blazor Server Hosted on IIS

I have a Blazor Server project that will be hosted on IIS.

I was using this tutorial by IAmTimCorey to get data from SQL Server. This worked perfectly, but now I want to add another data source to pull data from for different Razor Component (page).

I know how to add another connection string to appsettings.json, but how do I access the second data source and create a service (like Tim's video) to use the 2nd data source?


dotnet-csharpdotnet-aspnet-core-blazordotnet-adonet
· 2
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@MikaelaCaron-2451 As far as I know, if you want to add another datasrouce like the video shows, you should create another DataAccessLibrary and create all the logic in it and then you could register the second service like this
services.AddTransient<ISqlDataAccess2, SqlDataAccess2>( ); services.AddTransient<IStuData, StuData>(); and create a new blazor service.

1 Vote 1 ·

That makes sense! I wasn't sure if you could do it all in one project.

But having multiple projects for the different data sources sounds like a good solution. Thank you!!

0 Votes 0 ·

1 Answer

BrandoZhang-MSFT avatar image
0 Votes"
BrandoZhang-MSFT answered ·

That makes sense! I wasn't sure if you could do it all in one project.

But having multiple projects for the different data sources sounds like a good solution. Thank you!!



You could also put it all in one project, but you still need add the different data class and sql dat class.

But I don't suggest you use multiple database in one project. Normally, we will use just one database with multiple table in one project. Using multiple database in one project will make your project become more complex than before and may causing some develop risk.


If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


· 2 ·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks for the input! I'm going to create a project for each data source (accessing different databases).

However yes it is more complex, but the project I'm working on requires access to at least 7 different databases in different locations, so it is a complex project.

0 Votes 0 ·

I do not see having multiple databases in a single project like a Data Access Layer classlib project where each database code was implemented in each folder in a project would cause a problem.

By implementing the database in each folder in a project implements namespace seperation, and it eliminates any complications with having more than one database implemented in a project.

It's done all the time.

0 Votes 0 ·