asp.net2.0中读取web.config数据库连接字符串
2012-07-24 19:34
169 查看
关于数据库连接 数据库连接字符串一般放在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数据库连接字符串2种方法
- asp.net2.0中2种读取web.config数据库连接字符串
- asp.net2.0中读取web.config数据库连接字符串
- asp.net2.0中读取web.config数据库连接字符串2种方法
- asp.net2.0中2种读取web.config数据库连接字符串
- asp.net2.0中2种读取web.config数据库连接字符串
- asp.net2.0中读取web.config数据库连接字符串2种方法
- asp.net2.0中读取web.config连接字符串或是其他配置信息的方法
- 怎样从ASP.NET2.0中读取连接字符串的设置
- 怎样从ASP.NET2.0中读取连接字符串的设置
- Access数据库连接字符串读取,设置
- [导入]怎样从ASP.NET 2.0中读取连接字符串
- C# 读取 appconfig文件配置数据库连接字符串,和配置文件
- C# 使用OLEDB读取不同版本Excel数据的连接字符串
- 读取连接字符串
- Web.config数据库连接字符串密码中的一个字符导致连接数据库失败
- [导入].NET中使用三层构架如何从DAL层读取web.config中的数据库连接字符串!
- 在三层开发的DAL层中, 从web.config中读取数据库的连接字符串的方法
- C#2005如何读取XML文件中的数据库连接字符串??? (好像和2003不一样啊) 急,跪求!
- c#读取到web.config里的数据库连接字符串