如何使用一种方法来改变多个连接字符串值 [英] How to change multiple connection string value using one method
问题描述
我目前正在处理的是在LINQ的开发其数据检索结构的.Net系统。该系统是由其他开发商最后一次开发的,现在我处理的一个大问题。
I'm currently handling a .Net system that was developed in Linq for its data retrieval structure. This system was developed by other developers last time and I'm dealing a big problem now.
一个坏的做法(或者我只是不知道为什么要开发这样做),我发现从这个系统是这样的,在/应用程序数据/ DataContext的/,有很多的的.dbml文件,并在.designer.vb例如Product.designer.vb文件,由这片code的:
One of the bad practice (or i just not sure why must the developer do that) i found from this system is that, inside /AppData/DataContext/, there are alot of .dbml files and in the .designer.vb, for example Product.designer.vb file, consists of this piece of code:
Private Shared mappingSource As System.Data.Linq.Mapping.MappingSource = New AttributeMappingSource
Public Sub New()
MyBase.New(Global.System.Configuration.ConfigurationManager.ConnectionStrings("DBconstr").ConnectionString, mappingSource)
OnCreated
End Sub
我目前的主要挑战是,我需要改变到一个新的连接字符串名进行的所有DBconstr和点到另一个数据库,同时保持当前的Dbconstr在web.config中设置。有超过400线在整个系统中,我需要查找和替换如果我有做手工。所以,我需要咨询是否有什么办法可以改变使用一个或几个直接的方法都硬codeD连接字符串,而不是手动更改所有400行以上?
My current major challenge is, I need to change to a new connection string name for all DBconstr and point to another database while keeping the current "Dbconstr" setting in web.config. There are over 400 lines in the entire system I need to find and replace if i have to do it manually. So I need advice if there is any way i can change all hard-coded connection string using one or few direct methods instead of changing all 400 plus lines manually?
我曾想过调用的.master页面一定的方法和覆盖.ConnectionString的价值为所有的子页面,但不知道这是可能的。
I had thought about calling certain method in .Master page and override the value of .ConnectionString for all the child pages but not sure if this is possible.
请指教。谢谢
推荐答案
您应该看看这个:<一href=\"http://blogs.msdn.com/b/webdev/archive/2009/05/04/web-deployment-web-config-transformation.aspx\" rel=\"nofollow\">http://blogs.msdn.com/b/webdev/archive/2009/05/04/web-deployment-web-config-transformation.aspx.它说明了如何使用web.config中转型。它基本上允许修改设置的值(即连接字符串),这取决于您的解决方案/生成配置。结果
修改对飞的配置文件是不是试图修改它在code容易多了。
You should have a look at this: http://blogs.msdn.com/b/webdev/archive/2009/05/04/web-deployment-web-config-transformation.aspx. It explains how to use web.config transformation. It basically allows modifying the value of a setting (ie. connection strings) depending on your solution/build configuration.
Modifying the configuration file "on the fly" is much easier than trying to modify it in the code.
您也应该检查我提供了关于同一主题的这两个答案:
You should also check these two answers I provided on the same topic:
- 如何为我的本地机器不同的web.config设置? -
<一href=\"http://stackoverflow.com/a/19294499/375304\">http://stackoverflow.com/a/19294499/375304 - 申请的web.config变换局部 - <一个href=\"http://stackoverflow.com/a/19301084/375304\">http://stackoverflow.com/a/19301084/375304
这篇关于如何使用一种方法来改变多个连接字符串值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!