如何更改 Castle ActiveRecord 使用的连接

发布于 2024-07-26 01:39:24 字数 333 浏览 2 评论 0原文

我有一个使用 ActiveRecord 构建的应用程序,其中有一个新要求,即允许用户在应用程序运行过程中的不同时间选择他们希望操作的数据库。

数据库连接是在 ActiveRecordStart.Initalize 调用中设置的。 我希望每当用户选择使用新数据库时都能够更改此连接。 但是,我看不出有什么办法可以做到这一点。

DifferentDatabaseScope 确实允许使用不同的连接,但只会覆盖 Initialize 调用中的连接设置,并且必须用于每个 ActiveRecord 调用,数量为数百个,因此不太理想。

我不知道有什么方法可以更改在初始化中设置的“基本”连接吗?

I have an application build using ActiveRecord for which there is a new requirement to allow the user to select a database they wish to operate at various times in the course of the running of the application.

The database connection is set up in the ActiveRecordStart.Initalize call. I would like to be able to change this connection whenever the user selects to work with a new database. However, I can see no way of doing this.

DifferentDatabaseScope does allow the use of a different connection, but only overrides the connection setup in the Initialize call and has to be used for each ActiveRecord call, which number hundreds, so is less than ideal.

This there some way I am not aware of to change the 'base' connection that is set up in the Initialize?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

極樂鬼 2024-08-02 01:39:25

如果不同的数据库范围还不够,请尝试编写自定义 IConnectionProvider< /a> 创建一个指向用户选择的数据库的 IDbConnection。

If Different Database Scope is not enough try writing a custom IConnectionProvider that creates a IDbConnection pointing to the user-selected database.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文