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

Reading number is top 10 articles
了解PHP处理复杂数学问题的10个PEAR类_php资料_编程技术
技术畅谈:开发大型PHP项目的技巧与方法_php资料_编程技术
PHP数组的定义、初始化和数组元素的显示_php资料_编程技术
ASP.NET中Multi——ListBox控件编程详解_.net资料_编程技术
Excel在.Net下驻留内存的解决方法_.net资料_编程技术
收集ASP转ASP.NET过程典型问题_[Asp.Net教程]
SQL查询语句对象化的实现(C#)_[SQL,Server教程]
PHP编程技巧:看实例学正则表达式_[PHP教程]
php下免费的加速器,PHP,Accelerator_php资料_编程技术
ASP.NET&Spring.NET&NHibernate最佳实践(一)——目录_[Asp.Net教程]
Reading number is top 10 pictures
赵惟依写真3
Extremely rare TianShan Mountains snow lotus2
Female star bikini
Ashlynn Brooke a group sexy photo3
Female model behind the bitterness, often being overcharged2
2015中美最新武器装备巅峰对决!
The Soviet union swimsuit exposure in the 70 year2
A man's favorite things12
Plump, too plump!2
Li Zongrui hunting video screenshots2
Download software ranking
Boxer Classic video2
Tram sex maniac 2 (H) rar bag4
致我们终将逝去的青春
美女写真2
功夫熊猫2(下集)
Tram sex maniac 2 (H) rar bag9
Such love down(擒爱记)
传奇私服架设教程
Proficient in JavaScript
Desire a peach blossom
delv published in(发表于) 2014/1/10 6:31:55 Edit(编辑)
怎样从ASP.NET,2.0中读取连接字符串的设置_[Asp.Net教程]

怎样从ASP.NET,2.0中读取连接字符串的设置_[Asp.Net教程]

怎样从ASP.NET 2.0中读取连接字符串的设置_[Asp.Net教程]

在ASP.NET 2.0中,使用了一种在运行时解析为连接字符串值的新的声明性表达式语法,按名称引用数据库连接字符串。连接字符串本身存储在 Web.config 文件中的 <connectionStrings> 配置节下面,以便易于在单个位置为应用程序中的所有页进行维护。


  范例程序代码如下:


<?xml version="1.0"?>
<configuration>
<connectionStrings>
<add name="Pubs" connectionString="Server=localhost;
Integrated Security=True;Database=pubs;Persist Security Info=True"
providerName="System.Data.SqlClient" />
<add name="Northwind" connectionString="Server=localhost;
Integrated Security=True;Database=Northwind;Persist Security Info=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
<pages styleSheetTheme="Default"/>
</system.web>
</configuration>


 程序代码说明:在上述范例的程序代码中,我们在Web.Config文件中的<connectionStrings> 配置节点下面设置了两个数据库连接字符串,分别指向pubs和Northwind两个示例数据库。注意,在2.0中引进了数据源控件,例如SqlDataSource 控件,我们可以将SqlDataSource 控件的 ConnectionString 属性被设置为表达式 <% ConnectionStrings:Pubs %>,该表达式在运行时由 ASP.NET 分析器解析为连接字符串。还可以为SqlDataSource 的 ProviderName 属性指定一个表达式,例如 <% ConnectionStrings:Pubs.ProviderName %>。其具体的用法和新特征将在以后的章节进行详细的介绍。现在有个基础的了解即可。


  当然,我们也可以用下面的方式从配置文件直接读取数据库连接字符串。首先我们需要引用using System.Web.Configuration命名空间,该命名空间包含用于设置 ASP.NET 配置的类。
string connectionString =ConfigurationManager.ConnectionStrings["Northwind"].ConnectionString;
程序代码说明:在上述范例的程序代码中,我们可以利用ConnectionStrings["Northwind"]读取相应的Northwind字符串。同理以可以利用ConnectionStrings["Pubs"]读取相应的Pubs字符串。


来源:网络







添加到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.