如何在 Spring.NET 中设置动态数据源
我正在开发一个项目,每次有新客户进来时,都会为该特定客户创建一个新数据库。在设置数据源时,通常是这样完成的:
<?xml version="1.0" encoding="utf-8"?>
<objects xmlns="http://www.springframework.net"
xmlns:db="http://www.springframework.net/database">
<db:provider id="globalDBProvider"
provider="SqlServer-1.1"
connectionString="Server=myServer;Database=myGloba lDB;Uid=user1;Pwd=user1"/>
<object id="globalAdoTemplate" type="Spring.Data.Generic.AdoTemplate, Spring.Data">
<property name="DbProvider" ref="globalDBProvider"/>
</object>
这对于我的“主”数据库来说效果很好,因为我知道数据库名称。但是,对于我的“新”数据库。我想知道是否有人对如何动态插入连接字符串有想法?例如,假设用户登录并单击 Client1 信息。 Client1 信息存储在其自己的数据库中。
我认为我需要为客户端提供另一个 dbprovider。但是如何设置它才能在运行时插入数据库和凭据呢?
I'm working on a project wherein each time a new client comes in, a new database is created for that specific client. In setting up the datasource, it is normally done this way:
<?xml version="1.0" encoding="utf-8"?>
<objects xmlns="http://www.springframework.net"
xmlns:db="http://www.springframework.net/database">
<db:provider id="globalDBProvider"
provider="SqlServer-1.1"
connectionString="Server=myServer;Database=myGloba lDB;Uid=user1;Pwd=user1"/>
<object id="globalAdoTemplate" type="Spring.Data.Generic.AdoTemplate, Spring.Data">
<property name="DbProvider" ref="globalDBProvider"/>
</object>
That works fine for my "master" database since I know the database name. However, for my "new" databases. I was wondering if anyone has ideas on how to plugin the connectionString dynamically? E.g. suppose a user logs in and clicks on Client1 information. The Client1 information is stored in its own database.
I assume that I'd need to have another dbprovider for the client. But how to set it up such that it'll plugin the database and credentials at runtime?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否考虑过实现 Spring.NET 附带的其他 IDbProvider 实现之一?
查看文档此处。
Have you taken a look at implementing one of the other IDbProvider implementations that come with Spring.NET?
Have a look at the documentation here.