Single website multiple databases, database switching

前端 未结 2 1932
长情又很酷
长情又很酷 2020-12-18 12:04

I have created a content management system (CMS) for my company’s product databases. The CMS is based on asp.net scaffolding with many custom pages and actions mixed in. We

2条回答
  •  南笙
    南笙 (楼主)
    2020-12-18 12:26

    Create another database for user to database mapping. The structure would be like so:

    database UserMap 
    
        table Users
           username (composite primary key)
           dbID (composite primary key, foreign key to "Databases" table)
    
        table Databases
           dbID (primary key)
           connectionString
    

    Then,

    1. populate the list of database in table "Databases"
    2. Do your SQL work to copy the users from the other websites into this "UserMap" database
    3. Write a trigger in each CMS database to add or remove a user as they are created or removed in their respective CMS so it updates the "UserMap" database
    4. Modify your code on the CMS(s) to use this single database for lookup to what connection string should be used.

    This would allow you to rely on the single database for the lookup and switch between them in a managed fashion going forward. It requires some up front work but after the triggers are there, you don't have to do anything more.

提交回复
热议问题