Skip to content

如何动态切换数据库连接字符串? #354

@TroyBug

Description

@TroyBug

目前有这样的需求,根据用户输入的连接字符串来连接到不同的数据库
我采用下面的方式根据用户输入的connStr重新设置连接

DBServerProvider.DbContext.Database.SetConnectionString(connStr)

但是访问到的数据还是旧的连接,请问大佬,如何让切换立即生效?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions