ASP.NET数据库连接字符串写在config.web配置文件中
2010-08-01 03:44
1056 查看
方法一:
方法二:
]//1 在web.config的conafiguration里面添加 <configuration> <appSettings> <add key="SqlConString" value="server=diablota;database=dbmessage;uid=sa;pwd="/> </appSettings> <connectionStrings/> //2 新建类库Data.cs里面的SqlConString静态私有属性读取配置文件 using System.Configuration; public class Data { private Data() { } public static string SqlConString { get { return ConfigurationManager.AppSettings["SqlConString"]; } } } //3 实例化的时候调用,静态方法直接调用 SqlConnection sqlcon = new SqlConnection(Data.SqlConString)
方法二:
]//1 在web.config中添加配置信息 <configuration> <connectionStrings> <add name="conStr" connectionString="server=localhost;database=master;uid=sa;pwd="/> </connectionStrings> </configuration> //2 添加引用 //引用程序集添加引用->选.Net下的->System.configuration //导入命名空间System.Configuration //3 获取连接字符串 public static string GetConStr() { //读取配置文件的字符串 ConnectionStringSetting setting = ConfigurationManager.ConnectionStrings["conStr"] //或者 ConfigurationManager.ConnectionStrings["constr"].ConnectionString; }
相关文章推荐
- ASP.NET数据库连接字符串写在config.web配置文件中(2)
- ASP.NET数据库连接字符串写在config.web配置文件中
- ASP.NET数据库连接字符串写在config.web配置文件中(1)
- 在ASP.NET项目中的web.config文件里配置数据库连接并在程序代码中获取连接字符串
- 在ASP.NET项目中的web.config文件里配置数据库连接并在程序代码中获取连接字符串
- ASP.NET项目中的web.config文件里配置数据库连接并在程序代码中获取连接字符串
- 【ASP.NET】将数据库连接字符串写在Web.config
- ASP.NET web.config中数据库连接字符串connectionStrings节的配置方法
- ASP.NET web.config中数据库连接字符串connectionStrings节的配置方法
- ASP.NET web.config中数据库连接字符串connectionStrings节的配置方法
- ASP.NET web.config中数据库连接字符串connectionStrings节的配置
- ASP.NET通过配置Web.config文件提高手动绑定数据库效率的一个简单方法,不用每次手动连接数据库地址,或者数据库地址变更时只改一处即可。
- ASP.NET web.config中数据库连接字符串connectionStrings节的配置方法
- Asp.net中Web.config连接字符串及配置数据库sqlserver
- Asp.net中Web.config连接字符串及配置数据库sqlserver .
- Asp.net中Web.config连接字符串及配置数据库sqlserver 浮兮vip解析
- ASP.NET web.config中数据库连接字符串connectionStrings节的配置方法
- Asp.net中Web.config连接字符串及配置数据库sqlserver
- ASP.NET中使用web.config配置web应用程序中的数据库连接
- ASP.NET配置(web.config)无法连接到SQL Server 数据库的解决方法