简体   繁体   English

在MVC3项目中更改数据库有多容易?

[英]How easy is it to change DB in a MVC3 project?

Basically I have made a MVC3 application that connects to and updates a database that exsists on a server. 基本上,我已经制作了一个MVC3应用程序,该应用程序连接到服务器上存在的数据库并进行更新。 This database is a test one however, and when I roll out the project live I need it to connect to the actual database. 但是,该数据库是一个测试数据库,当我实时上线项目时,我需要它连接到实际的数据库。 My question is how hard would it be to change the project/application to point at this new database? 我的问题是,更改项目/应用程序以指向该新数据库将有多困难?

I used the database first method, and am aware I would need to change my connection string. 我使用数据库优先方法,并且知道我需要更改连接字符串。 I feel it is unlikely to be as simple as that. 我觉得不可能这么简单。

Any help, tips or tutorials would be greatly appreciated. 任何帮助,技巧或教程,将不胜感激。

只要数据库结构是相同的,它只是这么简单。

You just need to change the connection string. 您只需要更改连接字符串。

Additionaly if you would like to deploy 2 versions of the website, each using it's own connection strings (for example for developpement and production) you can create 2 web.config files. 另外,如果您想部署2个版本的网站,每个版本都使用其自己的连接字符串(例如,用于开发和生产),则可以创建2个web.config文件。 Refer to this link SO question 参考此链接SO问题

It shouldn't be that hard. 不应该那么难。 You just need to make sure that the database that you are working on now and the database that you are changing to are equal in table names and column names otherwise you are going to have configure it to use the new database tables and columns. 您只需要确保您正在使用的数据库和要更改的数据库在表名和列名上是相等的,否则您将需要配置它以使用新的数据库表和列。

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

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