具有不同数据库的Web应用程序 [英] Web Application with different Databases

查看:78
本文介绍了具有不同数据库的Web应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我想创建一个Web应用程序,如果明天我的新客户有不同的数据库。因此,只需最少的配置,我就应该连接它。

例如



我创建了一个使用SQL的Web应用程序和客户端然后如果另一个客户接近与oracle等不同的数据库。所以,我应该提供一个层,使应用程序可以与Oracle和SQL一起工作(不是同时......独立)



我期待实体框架代码第一个模型,其中模型将在运行时创建DB。那么,如果你们有其他更好的方式,请告诉我。

谢谢

Hi All,

I want to create one web application in such a way that if tomorrow my new customer have different database . So,with minimal configuration I should connect to it.
E.g.

I created one web application and client using SQL then if another customer approaches with different database like oracle. So, I should provide a layer in such a way that application should work with Oracle and SQL (Not simultaneously ..independently)

I am looking forward with Entity Framework Code First Model where model will create DB in runtime. So, if you guys have any other better way then let me know .
Thanks

推荐答案

你可以使用像数据库无关的技术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.


这篇关于具有不同数据库的Web应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆