Store Connection String in Web.config
来源:互联网 发布:anti spam 知乎 编辑:程序博客网 时间:2024/06/08 14:12
Connection string in .NET 2.0 config file
In the appSettings location, add a key named whatever you like to reference your connection string to.
<appSettings><add key="myConnectionString" value="server=localhost;database=myDb;uid=myUser;password=myPass;" /></appSettings>
To read the connection string from code, use the ConfigurationSettings class.
string connStr = ConfigurationSettings.AppSettings("myConnectionString");
Now you have the connection string loaded from web.config into your string variable in code.
Connection string in .NET 3.5 (and above) config file
Do not use appsettings in web.config. Instead use the connectionStrings section in web.config.
<connectionStrings><add name="myConnectionString" connectionString="server=localhost;database=myDb;uid=myUser;password=myPass;" /></connectionStrings>
To read the connection string into your code, use the ConfigurationManager class.
string connStr = ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString;
Remember to add reference to the System.Configuration component. Then include the namespace ("using System.Configuration;" in C# and "imports System.Configuration" in VB.Net) in your code to get access to the ConfigurationManager class.
- Store Connection String in Web.config
- Store Your Database Connection String in Web.Config...
- 从web.config提取connection string
- 通过web.config调用connection string
- Connection with Web.config
- Using connection strings from web.config in ASP.NET v2.0
- AppSettings In web.config
- AppSettings In web.config
- Membership configure in web.config
- nettier setup, in web.config
- web.config in WCF Rest
- <jsp-config> in web.xml
- vs项目发布时提示类似Default-Web.config Connection String”参数不能为 Null 或空的报错问题
- WCF Server Configuration in Web.config or App.config
- config the Cache in the file of Web.Config
- SiteMap config vs. Web.config in page security right definition
- register controls in your web.config file
- Registering Your Controls in Web.config
- Perl的时间处理
- 无线技术知识 2.4G与其他无线技术对比
- PHP 实现万年历 支持查询
- jQuery LigerUI 插件介绍及使用之ligerTree
- 一个大牛的系列文章:An intro to modern OpenGL. Chapter 3: 3D transformation and projection
- Store Connection String in Web.config
- 关于定义宏
- MongoDB 学习笔记
- 现在的企业是不是以面试为基础,存在一些欺诈行为那?
- 一个大牛的系列文章:An intro to modern OpenGL. Chapter 4: Rendering a Dynamic 3D Scene with Phong Shading
- 图像分割之(一)概述
- 线程(五)–sleep和wait的区别
- Delphi和BC++程序手动查找按钮事件
- 简单的ajax评论完整代码