web.config中数据库连接字符串设置
2005-11-20 15:49
621 查看
定义在web.config中的<appSettings>元素中的键值可被所有子文件夹中的aspz文件使用.方便修改多个aspx文件的数据.
以数据库连接为例:
1,
web.config中
...
</system.web>
<appSettings>
<add key = "Nwind"
value = "server=(local)/NetSdk;database=Northwind;integrated security=true;"/>
</appSettings>
</configuration>
在aspx文件中引用它:
string strConn = ConfigurationSettings.AppSettings["Nwind"];
2,
可以通过以下方法来获取数据库在远程主机的真实目录物理路径。假定,在上传远程空间的域名地址如下:
http://www.kurama.com.cn/blog
3,
使用asp.net编程会使用到Server.MapPath相对路径.
暂时想到一个简单的解决办法:
web.config中
<appSettings>
<add key = "accPath" value = "provider = microsoft.Jet.OLEDB.4.0;Data Source=" />
<add key = "accName" value = "account.mdb" />
</appSettings>
aspx中
string strPath = ConfigurationSettings.AppSettings["accPath"];
string strName = ConfigurationSettings.AppSettings["accName"];
string strConn = strPath + Server.MapPath(strName);
以数据库连接为例:
1,
web.config中
...
</system.web>
<appSettings>
<add key = "Nwind"
value = "server=(local)/NetSdk;database=Northwind;integrated security=true;"/>
</appSettings>
</configuration>
在aspx文件中引用它:
string strConn = ConfigurationSettings.AppSettings["Nwind"];
2,
可以通过以下方法来获取数据库在远程主机的真实目录物理路径。假定,在上传远程空间的域名地址如下:
http://www.kurama.com.cn/blog
3,
使用asp.net编程会使用到Server.MapPath相对路径.
暂时想到一个简单的解决办法:
web.config中
<appSettings>
<add key = "accPath" value = "provider = microsoft.Jet.OLEDB.4.0;Data Source=" />
<add key = "accName" value = "account.mdb" />
</appSettings>
aspx中
string strPath = ConfigurationSettings.AppSettings["accPath"];
string strName = ConfigurationSettings.AppSettings["accName"];
string strConn = strPath + Server.MapPath(strName);
相关文章推荐
- 在Web.config里设置数据库连接字符串
- webConfig的设置和数据库连接字符串
- asp.net2.0中获得web.config中数据库连接字符串的2种方法
- web.config connectionStrings 数据库连接字符串的解释(转载)
- 在ASP.NET项目中的web.config文件里配置数据库连接并在程序代码中获取连接字符串
- 获取web.config中数据库连接字符串的2种方法
- web.config的设置,数据库连接语句(基本)!
- [转]web.config保护连接字符串及其它设置信息
- Acess数据库连接字符串如何存放在Web.config中?
- C#中如何读取webconfig.xml里的数据库连接字符串
- 怎样从web.config中读取连接字符串的设置
- ASP.NET数据库连接字符串写在config.web配置文件中(1)
- Asp.net中Web.config连接字符串及配置数据库sqlserver .
- ASP.NET数据库连接字符串写在config.web配置文件中(2)
- web.config connectionStrings 数据库连接字符串的解释(转载)
- web.config connectionStrings 数据库连接字符串的解释(转载)
- web.config 数据库连接字符串详解
- web.config connectionStrings 数据库连接字符串的解释
- web.config配置连接数据库字符串
- ACCESS在Web.config里设置连接字符串