asp.net2.0中读取web.config数据库连接字符串
来源:互联网 发布:淘宝上如何发布宝贝 编辑:程序博客网 时间:2024/05/18 03:15
关于数据库连接
数据库连接字符串一般放在web.config文件中
方式有两种
第一种:建立AppSettings节点
<appSettings>
<!-- Sql数据库连接字符串 -->
<add key="SqlConnectionStr" value="server=.;uid=sa;password=123;database=Fire" />
<add key="SqlConnectionStr2" value="" />
</appSettings>
第二种:在connectionStrings节点配置
<connectionStrings>
<add name="book" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\dragonsea\website\book\book\App_Data\book.mdb"
providerName="System.Data.OleDb" />
</connectionStrings>
文件中获取连接字符串
针对第一种方式要通过AppSettings来获取
第一种方式: string strConn = ConfigurationSettings.AppSettings["SqlConnectionStr"];
第二种方式: string strConn = ConfigurationManager.AppSettings["SqlConnectionStr"];
针对第二种方式:
string strConn = ConfigurationManager.ConnectionStrings["book"].ToString();
string connString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["SqlConnStr"].ConnectionString;
web.config文件:
<connectionStrings>
<remove name="LocalSqlServer" />
<add name="SqlConnStr" connectionString="user id=sa;password=sa;initial catalog=YktSms;data source=bing\sql2000" />
</connectionStrings>
- asp.net2.0中读取web.config数据库连接字符串
- asp.net2.0中读取web.config数据库连接字符串2种方法
- asp.net2.0中2种读取web.config数据库连接字符串
- asp.net2.0中读取web.config数据库连接字符串2种方法
- asp.net2.0中获得web.config中数据库连接字符串的2种方法
- ASP.NET2.0中通过web.config设置数据库连接串
- asp.net2.0中读取web.config的方法
- asp.net2.0中获取web.config中的连接字符串
- WinForm 读取Web.config 中数据库连接字符串
- 对asp.net2.0网站web.config中的数据库连接字符串加密
- 对asp.net2.0网站web.config中的数据库连接字符串加密
- 对asp.net2.0网站web.config中的数据库连接字符串加密
- 对asp.net2.0网站web.config中的数据库连接字符串加密
- 对asp.net2.0网站web.config中的数据库连接字符串加密
- asp.net2.0中加密web.config
- ASP.net2.0中数据库连接字符串
- WebService如何从Web.Config中读取数据库连接字符串
- web.config中定义数据库连接字符串以及读取方法
- 静态数组实现双向栈
- 利用静态库实现控件封装
- 【100题】斐波那契数列(3)-----数学归纳法
- 二叉树的实现
- error C2143: syntax error : missing ';' before 'type'
- asp.net2.0中读取web.config数据库连接字符串
- TEA Algorithm Implementation on iOS
- USCAO section 1.4 The Clocks
- IOS 如何保存图片到document实例
- IOS UIScrollView
- intent中取得mimetype
- 孩子兄弟表示法实现树
- IOS 如何保存图片到相册实例
- oracle wallet使用与维护---oracle无密码登录