Web.Config文件设置如下:

从ASP.NET 2.0中读取连接字符串的设置<?xml version="1.0"?>
从ASP.NET 2.0中读取连接字符串的设置
<!-- 
从ASP.NET 2.0中读取连接字符串的设置    注意: 除了手动编辑此文件以外,您还可以使用 
从ASP.NET 2.0中读取连接字符串的设置    Web 管理工具来配置应用程序的设置。可以使用 Visual Studio 中的
从ASP.NET 2.0中读取连接字符串的设置     “网站”->“Asp.Net 配置”选项。
从ASP.NET 2.0中读取连接字符串的设置    设置和注释的完整列表在 
从ASP.NET 2.0中读取连接字符串的设置    machine.config.comments 中,该文件通常位于 
从ASP.NET 2.0中读取连接字符串的设置    \Windows\Microsoft.Net\Framework\v2.x\Config 中
从ASP.NET 2.0中读取连接字符串的设置
-->
从ASP.NET 2.0中读取连接字符串的设置
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
从ASP.NET 2.0中读取连接字符串的设置  
<connectionStrings>
从ASP.NET 2.0中读取连接字符串的设置    
<add name="pubs" connectionString="server=localhost;database=pubs;" providerName="System.Data.SqlClient"/>
从ASP.NET 2.0中读取连接字符串的设置    
</connectionStrings>
从ASP.NET 2.0中读取连接字符串的设置    
<system.web>
从ASP.NET 2.0中读取连接字符串的设置        
<!-- 
从ASP.NET 2.0中读取连接字符串的设置            设置 compilation debug="true" 将调试符号插入
从ASP.NET 2.0中读取连接字符串的设置            已编译的页面中。但由于这会 
从ASP.NET 2.0中读取连接字符串的设置            影响性能,因此只在开发过程中将此值 
从ASP.NET 2.0中读取连接字符串的设置            设置为 true。
从ASP.NET 2.0中读取连接字符串的设置        
-->
从ASP.NET 2.0中读取连接字符串的设置  
<compilation debug="true"/>
从ASP.NET 2.0中读取连接字符串的设置        
<!--
从ASP.NET 2.0中读取连接字符串的设置            通过 <authentication> 节可以配置 ASP.NET 使用的 
从ASP.NET 2.0中读取连接字符串的设置            安全身份验证模式,
从ASP.NET 2.0中读取连接字符串的设置            以标识传入的用户。 
从ASP.NET 2.0中读取连接字符串的设置        
-->
从ASP.NET 2.0中读取连接字符串的设置        
<authentication mode="Windows"/>
从ASP.NET 2.0中读取连接字符串的设置        
<!--
从ASP.NET 2.0中读取连接字符串的设置            如果在执行请求的过程中出现未处理的错误,
从ASP.NET 2.0中读取连接字符串的设置            则通过 <customErrors> 节可以配置相应的处理步骤。具体说来,
从ASP.NET 2.0中读取连接字符串的设置            开发人员通过该节可以配置
从ASP.NET 2.0中读取连接字符串的设置            要显示的 html 错误页
从ASP.NET 2.0中读取连接字符串的设置            以代替错误堆栈跟踪。
从ASP.NET 2.0中读取连接字符串的设置
从ASP.NET 2.0中读取连接字符串的设置        <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
从ASP.NET 2.0中读取连接字符串的设置            <error statusCode="403" redirect="NoAccess.htm" />
从ASP.NET 2.0中读取连接字符串的设置            <error statusCode="404" redirect="FileNotFound.htm" />
从ASP.NET 2.0中读取连接字符串的设置        </customErrors>
从ASP.NET 2.0中读取连接字符串的设置        
-->
从ASP.NET 2.0中读取连接字符串的设置    
</system.web>
从ASP.NET 2.0中读取连接字符串的设置
</configuration>
  我们可以用下面的方式从配置文件直接读取数据库连接字符串,
从ASP.NET 2.0中读取连接字符串的设置using System.Configuration;
从ASP.NET 2.0中读取连接字符串的设置
从ASP.NET 2.0中读取连接字符串的设置
string cons;
从ASP.NET 2.0中读取连接字符串的设置cons
=ConfigurationManager.ConnectionStrings["pubs"].ConnectionString;
参照:http://www.knowsky.com/340324.html

相关文章: