Blazor server side. Client side with DB connections

TheHoneyBadgers 1 Reputation point
2022-04-08T11:44:10.223+00:00

Hello,

I am working on a Blazor server side application.
Now do I use multiple databases on different part of the website.
How is it possible that client A that is on a page that use Database Z stays connected while client B on Database Y is also connected?
Both pages are being build fine and both has a call to the database every second.
So when client A is on the page it is getting updated with the new data from the databse every second. But when client B goes to another page that uses Database Y. Connection to database Z is stopped and client A does not get an updated page anymore (till refresh but than the same goes for client B they don't get an error because of the catch that I use).
Is there a way for every client to keep connected to the database that is needed for that page or pages? So that when client C goes to another page that uses either database Z,Y or maybe even X that they don't interfere with each other?

If there is a tutorial available somewhere please let me know. I've tried a few but couldn't implement it in Blazor server side. If it is not possible let me know as well.
Thanks in advance

Windows development Internet Information Services
Developer technologies .NET Blazor
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Olaf Helper 47,436 Reputation points
    2022-04-08T12:36:00.94+00:00

    Is there a way for every client to keep connected to the database that is needed for that page or pages?

    Not the web client accessing the database, it's the blazor backend and web backend normally work stateless = no permanent connection.

    If it is not possible let me know as well.

    Indeed; you have to rethink your application design.

    1 person found this answer helpful.
    0 comments No comments

  2. Bruce (SqlWork.com) 77,686 Reputation points Volunteer Moderator
    2022-04-09T15:02:56.78+00:00

    Unlike regular websites, blazor server apps have dedicated state, tied to the signal/r connection, but not a dedicated thread.

    So, there is no technical reason your code won’t work. It sound like you are not managing the database connections properly.

    0 comments No comments

  3. Michael Washington 921 Reputation points MVP
    2022-04-11T23:20:30.333+00:00

    You would not have (or need) a separate database for each user.

    All your users would use the same database. For a tutorial see: Creating A Step-By-Step End-To-End Database Server-Side Blazor Application (updated to .Net 6)

    You can open up the app in multiple web browsers, and create and log in as different users.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.