All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
IIS7,会重用那些不该重用,HttpHandler_.net资料_编程技术
asp.net,2.0,下的表单验证Cookieless属性_.net资料_编程技术
SQL,Server,2000企业版安装教程_mssql学习_编程技术
在asp.net中实现删除DataGrid的某条记录时的提示信息_.net资料_编程技术
轻松掌握Ajax.net系列教程二:部署Ajax,Control,Toolkit_[Asp.Net教程]
PHP强制对象类型之instanceof操作符_php资料_编程技术
asp.net1.1和asp.net,2.0共存_[Asp.Net教程]
在asp.Net,中把图片存入数据库_[Asp.Net教程]
一步步教你配置SQL SERVER合并复制(一)概念介绍_[SQL Server教程]
SQL中CASE的用法_[SQL,Server教程]
Reading number is top 10 pictures
Sora aoi possession of boudoir2
漂亮脸蛋魔鬼身材2
2012 national geographic daily picture1
Sora aoi on twitter5
职场回春术
美女浴室写真3
A man's favorite things11
Plump, too plump!2
30 beautiful school beauty6
Small QiShu -- ShuangShuangPan1
Download software ranking
变速齿轮3.26
Boxer vs Yellow2
Twenty piece of palm leaf
Call Of Duty5
Love the forty days
Sora aoi's film--cangkong_Blue.Sky
C#编程思想
Wild things 2
都市狐狸姑娘传
asp.netWeb服务器高级编程
归海一刀 published in(发表于) 2014/1/30 1:30:42 Edit(编辑)
两种ASP.Net数据库连接设置和读取方法_[Asp.Net教程]

两种ASP.Net数据库连接设置和读取方法_[Asp.Net教程]

两种ASP.Net数据库连接设置和读取方法_[Asp.Net教程]
在这里我们介绍两种ASP.Net数据库连接设置和读取方法:web.config文件和 Gloab文件。

方法一:web.config文件
——设置:
在web.config文件里添加关键字key是通过标记来实现的,但是appSettings标记通常放在 .....标记外面。
例:








——读取:
要在代码中引用这些数据库连接字符串,需要先添加对System.ConFiguration名字空间的引用,在这个名字空间中含有ConfigurationSettings类,其静态方法ConfigurationSettings.AppSettings属性可获取web.config文件中节的设置,读到的值为string型。例如:

using System.Configuration;
string conn1 = ConfigurationSettings.AppSettings["connString1"];
string conn2 = ConfigurationSettings.AppSettings["connString2"];
SQLConnection myConn1 = new SQLConnection(conn1);
OleDbConnection myConn2 = new OleDbConnection(conn2);

在VS2005中, ConfigurationSettings.AppSettings 可以换成 ConfigurationManager.AppSettings

方法二:Gloab文件
——设置:
在Global文件里中添加

protected void Session_Start(Object sender, EventArgs e)
{
Session["sqlConnectionString"] = "uid=Username;pwd=password;database=MyTest;
server=Localhost;Connect Timeout=300";
}

——读取:
在代码中的应用:
String strConnection=Session["sqlConnectionString"].ToString();
sqlConnection_1=new SqlConnection(strConnection);

本文推荐使用第一种设计方式。


添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.