简体   繁体   English

使用多个数据库的单个ASP.NET MVC应用程序

[英]Single ASP.NET MVC application using multiple databases

I would like to build an application that connects to multiple databases. 我想构建一个连接到多个数据库的应用程序。

A customer would have an address to access your application (eg customer1.myproduct.com) and then this application accesses the database "customer1." 客户将有一个地址来访问您的应用程序(例如,customer1.myproduct.com),然后该应用程序将访问数据库“ customer1”。 Each customer would have their own database. 每个客户都有自己的数据库。

What better way to make these connections? 有什么更好的方式建立这些连接? What care should I take to have a good application performance? 为了获得良好的应用程序性能,我应该注意些什么?

There is nothing to stop you from having an ASP.NET app accessing multiple databases, in the web.config of the solution you can add multiple connection strings. 没有什么可以阻止您让ASP.NET应用程序访问多个数据库,在解决方案的web.config中,您可以添加多个连接字符串。 In the tag. 在标签中。

<connectionStrings>
    <add name="DefaultConnection" .....>
    <add name="EmployeeConnection" .....>
 </connectionString>

If I was you I would you use the "ADO.NET Entity model" with "Linq" to access the data, for good application performance it all depends on what you are doing, how much of it and for how long. 如果您是我,那么您将使用带有“ Linq”的“ ADO.NET实体模型”来访问数据,要想获得良好的应用程序性能,这全都取决于您在做什么,需要多少时间以及需要多长时间。 Best to check around when you get stuck or read up on some of the best practice on http://msdn.microsoft.com 最好四处查看,以免卡住或阅读http://msdn.microsoft.com上的一些最佳做法

Hope this helps. 希望这可以帮助。

that's a bad idea to have a database for each customer. 为每个客户建立一个数据库是一个坏主意。 how will you be handling creation of new database for each customer manually? 您将如何手动为每个客户处理新数据库的创建?

maintaining all these connections will not be an easy job. 维护所有这些连接将不是一件容易的事。

You can change the config file in the project or create new. 您可以在项目中更改配置文件或创建新文件。 I think you can change in config file only connectionString and it will be enough. 我认为您只能在配置文件中更改connectionString,这样就足够了。 When you want to change database you only change in: 当您想更改数据库时,只需更改:

<connectionStrings>
  ...
  connectionString="new connectionstring"
  ...
</connectionStrings>

Should be create small application for chage. 应创建小应用程序进行修改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM