怎样从ASP.NET2.0中读取连接字符串的设置
来源:互联网 发布:java拼接html字符串 编辑:程序博客网 时间:2024/06/05 19:08
范例程序代码如下:
<?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字符串。
http://www.cnblogs.com/interboy/archive/2006/08/21/482665.html
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>- 怎样从ASP.NET2.0中读取连接字符串的设置
- 怎样从ASP.NET2.0中读取连接字符串的设置
- 怎样从ASP.NET 2.0中读取连接字符串的设置
- 怎样从ASP.NET 2.0中读取连接字符串的设置新增方法
- 怎样从ASP.NET 2.0中读取连接字符串的设置
- 怎样从ASP.NET 2.0中读取连接字符串的设置
- 怎样从ASP.NET 2.0中读取连接字符串的设置
- 怎样从web.config中读取连接字符串的设置
- 怎样从ASP.NET 2.0中读取连接字符串
- asp.net2.0中读取web.config数据库连接字符串
- asp.net2.0中获取web.config中的连接字符串
- asp.net2.0中尝试读取无效值的错误
- asp.net2.0中读取web.config的方法
- asp.net2.0WebConfig的配置文件中设置数据库链接
- asp.Net2.0中TextBox只读的设置方法
- asp.net2.0中读取web.config数据库连接字符串2种方法
- asp.net2.0中2种读取web.config数据库连接字符串
- asp.net2.0中读取web.config数据库连接字符串2种方法
- ASP.NET中为DataGrid添加单选框
- .Net下几种日志管理方法
- ASP.NET2.0登陆控件的使用(常见的三种方法)
- ASP.NET2.0X64的奇怪问题
- ASP.NET2.0-EnterKey-DefaultSubmitButton
- 怎样从ASP.NET2.0中读取连接字符串的设置
- 一个极有可能引发ExecutionEngineException的情况
- ASP.NET服务器控件PleaseWaitButton[翻译]
- 用gridview显示来自excel表格里的数据
- ASP.NET2.0WebService中传递DataTable参考
- ASP.NET实现下拉框二级联动组件
- 如何解决Remoting无法传输存储过程参数的问题
- 在ExcuteReader中使用输出参数的问题
- asp.net错误处理封装