在运行时更改多租户应用程序的 XSD ConnectionString
我正在将我们的应用程序从“一组代码和一个数据库”更改为“一组代码到多个数据库(每个客户一个数据库)”。
原代码为VS2005 ASP.NET(VB)& 许多 XSD 位于单独的 DLL 中。 web.config 的 ConnectionString 将在运行时覆盖 DLL 中存储的连接字符串。
现在,每次声明数据适配器/数据集/表时,我都需要更改 ConnectionString,因为调用可能会转到与上次调用不同的数据库。
有人对此有任何提示吗?
I'm changing our application from "one set of code & one database" to "one set of code to multiple databases (one database per customer)".
The original code is VS2005 ASP.NET(VB) & lots of XSD's in a separate DLL. The web.config's ConnectionString would override the one stored in the DLL at runtime.
Now I need to change the ConnectionString every time I declare a Data adapter/Dataset/table, because the call could be going to a different database from the last call.
Has anyone got any hints on this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
还发现虽然提到的属性(ConnectionModifier)是Public,但当它是QueriesTableAdapter时,仍然无法通过代码看到它。 因此,我不得不花费相当长的时间删除它们并用普通的“使用查询”块替换它们。
另外,我确信该项目现在看起来更快。 这可能是尺寸的减小或者现在所有调用都使用“Using”(原始代码是在 .NET 时代的早期,所以一开始就可以写得更好)。
Also have found that although the property mentioned (ConnectionModifier) is Public, this still can't be seen via code when it is a QueriesTableAdapter. Therefore I had to spend quite a while removing these and replacing them with a normal "Using Query" block.
Also, I'm sure the project seems faster now. It could be the reduction in size or the use of "Using" with all the calls now (the original code was early in our .NET days so could have been written better in the first place).
经过一番研究,XSD 似乎有一个名为 ConnectionModifier 的属性。
要找到它,请在 XSD 图表上单击图表的 TableAdapter 部分(定义查询的位置)。
在属性窗口中,将 ConnectionModifier 更改为 Public,然后单击“保存”。 (这似乎也更改了该页面上所有数据集的属性。)
回到站点的主代码,您现在可以执行如下操作:
它只需要一个连接对象。
我还没有对此进行适当的测试! 不幸的是,每次从 XSD 声明某些内容时都必须传递一个新的连接对象。
After a bit of research, it seems that an XSD has a property called ConnectionModifier.
To find it, on your XSD diagram, click the TableAdapter part of the diagram (where the queries are defined).
In the properties window, change ConnectionModifier to Public and click Save. (This seems to change the property for all the Datasets on that page too.)
Back in the main code of your site you can now do something like this:
It only takes a connection object.
I have yet to give this a proper test! Unfortunatley, a new connection object will have to be passed every time you declare something from an XSD.