且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

具有不同数据库的Web应用程序

更新时间:2022-12-21 18:30:36

你可以使用像数据库无关的技术ADO.net和ODBC,这样你只需更改连接字符串中的odbc驱动程序,只要新数据库有一个adbc驱动程序,它就应该*正常工作。 odbc实现可能仍然存在一些细微差别,因此您可能需要从SQL调整。



鉴于这会对代码的性能产生负面影响对于一种永远不会发生的情况(微软在几年前就摆脱了这种类型的解决方案 - 一个问题 - 没有人),下一个***的方法是使用数据访问来抽象数据访问代码图层或存储库模式类型解决方案。当一个新的数据存储出现时,你需要为它重写数据层,但是如果你已经正确地完成了这一切,你需要重新编写它,你将能够使用任何数据访问图层取决于客户端使用的内容。 Google存储库模式或数据抽象模式以获取更多详细信息。
You can use a database-agnostic technology like ADO.net and ODBC, and that way you just change the odbc driver in your connection string and as long as the new database has an adbc driver it *should* just work. There might still be some minor differences in odbc implementation though so you might need to tweak from of the SQL.

Given that is going to adversely impact the performance of your code for a situation that is never going to happen (Microsoft moved away from this type of solution-for-a-problem-noone-has quite some years ago), the next best way would be to abstract your data access code using a data access layer, or a repository patter type solution. When a new data store comes along you'll need to rewrite the data layer for it, but if you've done it correctly that's all you'll need to re-write and you'll be able to use any of your data access layers depending what the client uses. Google repository pattern or data abstraction patterns for more details.


实体框架代码第一种方法是创建此类应用程序的最有名方法。您只需要更改连接字符串并完成。无需再次创建表。
Entityframework code first approach is the best known way to create such application. You just need to change connection string and done. No need to create tables again.


为包含主数据的所有表生成脚本并保持独立。您可以将此脚本放入带有数据库名称参数的master数据库中。当您需要创建新数据库时,可以使用数据库名称参数运行它。
Generate script for all table with master data and keep separate. this script you can place in sp into master database with parameter of database name. when you need to create new database then you can run it with your database name parameter.