Search code examples
sql-serverasp.net-mvcdatabasedatabase-connectionmultiple-databases

Different database for each user


We are building a web application using asp.net mvc and sql server 2012. The users of this application are sql developers, each of them have sql server installed in their local machines.

If user A opens the application, the data from User A's local sql server has to be displayed in the application.

If user B opens the application, the data from User B's local sql server has to be displayed in the application.

If a new users joins, the application has to point their database.

  • Is it possible to create such an web application which dynamically points to different databases?
  • If yes, what is the best approach for the same?
  • If yes, what are the pros and cons of this kind of web app?
  • If no, is windows/native application is the alternate approach?

Solution

  • Yes you can create sutch kind of app.

    First -> If you always connect to localDatabases you dont need to do anythink special, just in connection string say that you want to connect to local db on computer. In this approche every computer have its own database.

    You must remember that you must write a somekind of migration code that will be automaticly create a database on localMachine if sutch database don't exist.

    If you have database somewhere on server (and all user will be connect this server and use this database) you can in startup/init class just chose connection string that will be use to connect the db so you can have many instantion of the same db on server and just chose for what to connect.

    Acctualy i'm working in that kind of environment and it's fulfills it's goals.