基于web.config动态设置LINQ dbml 文件中的连接字符串
来源:互联网 发布:数据新常态 下载 编辑:程序博客网 时间:2024/06/06 07:28
Ideally, you want your LINQ database connection strings defined outside your compiled code and to be held in the Web.Config instead.
Unfortunately, by default, they are added to your Settings.cs file which is then compiled away into your code. This has the effect of reducing your ability to easily configure your applications for different environments (i.e., you would need to have different compiled DLLs for dev, test and production).
It is also LESS secure because you can easily use reflection to examine your DLLs for passwords - whereas you can encrypt the web.config so it is only viewable to people who have permissions to the IIS console. This is more difficult to break.
The recommendations to remedy this issue in the following MSDN bloghttp://blogs.msdn.com/jongallant/archive/2007/11/25/linq-and-web-application-connection-strings.aspx is slightly wrong. He suggests that you remove the default constructor in the designer. This is bad because you would have to fix up the file every time you regenerate your dbml file. Instead, you should use what is provided to you and set the property on the designer for "Application Settings" to false
and also do the following steps every time you will go for the drag and drop your stored procedure and user defined functions.
- Right click on any white space in dbml file.
- Click on properties option.
- Select drop down for Connection option in Properties window.
- Choose last option from drop down for Connection option which should be none.
- Close Properties window and press Save.
This allows you to define a default constructor in your own partial class that extends your dbml context designer classes like example:
In the above example, UserClassesDataContext
is the class name of the LINQ to SQL(DBML) file and WebConnectionString
is the name of the Connection String in Web.Config.
Happy coding.
原文:http://www.codeproject.com/Tips/189440/How-to-set-the-connection-string-in-your-LINQ-dbml.aspx
- 基于web.config动态设置LINQ dbml 文件中的连接字符串
- 调用web.config文件中的连接字符串
- Linq修改Web.config的连接字符串
- web.config中的连接字符串
- 动态修改Web.config连接字符串
- web.config 设置Oracle连接字符串
- 连接字符串设置(Web.config配置)
- 如何加密Web.Config中的连接字符串
- 如何加密Web.Config中的连接字符串
- 如何加密Web.Config中的连接字符串
- Web.config中的sqlserver连接字符串+读取
- web.config文件中连接字符串说明
- web.config 连接字符串
- 关于linq 中 的 dbml文件中的 对象加s 去s 的问题
- ACCESS在Web.config里设置连接字符串
- ACCESS在Web.config里设置连接字符串!
- 怎样从web.config中读取连接字符串的设置
- [转]web.config保护连接字符串及其它设置信息
- ARM GCC浮点相关总结
- 从《黑客和画家》中证实的观点
- iPhone开发进阶(11)--- 多线程的使用与注意事项
- 单片机和嵌入式系统linux的区别
- iPhone开发进阶(1) --- 深入理解iPhone OS/SDK与Objective-C 2.0
- 基于web.config动态设置LINQ dbml 文件中的连接字符串
- Linux0.11启动过程
- iPhone开发进阶(2) --- iPhone应用程序/项目的构成
- String_shod be so difficiult
- 批量响应消息处理
- iPhone开发进阶(3) --- iPhone应用程序的启动过程
- DC与GC的区别
- 简单工厂模式
- Android之Animation属性配置文件