为web.config写入数据库连接字符串的方法
来源:互联网 发布:kyocera驱动下载 mac 编辑:程序博客网 时间:2024/06/03 15:48
1.写入连接字符串
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
// Create a new ConnectionStringSettings object and populate it
ConnectionStringSettings conn = new ConnectionStringSettings();
conn.ConnectionString =
"Server=localhost;User ID=sa;Password=123456; " +
"Database=Northwind;Persist Security Info=True";
conn.Name = "AppConnectionString2";
conn.ProviderName = "System.Data.SqlClient";
// Add the new connection string to the web.config
Configuration config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("example");
config.ConnectionStrings.ConnectionStrings.Add(conn);
config.Save();
}
}
2.修改连接字符串
protected void Page_Load(object sender, EventArgs e)
{
// Retrieve an existing connection string into a Connection String Builder
System.Data.SqlClient.SqlConnectionStringBuilder builder = new
System.Data.SqlClient.SqlConnectionStringBuilder();
// Change the connection string properties
builder.DataSource = "localhost";
builder.InitialCatalog = "Northwind1";
builder.UserID = "sa";
builder.Password = "password";
builder.PersistSecurityInfo = true;
// Save the connection string back to the web.config
Configuration config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("/Chapter11");
config.ConnectionStrings.ConnectionStrings["AppConnectionString1"].ConnectionString =
builder.ConnectionString;
config.Save();
}
- 为web.config写入数据库连接字符串的方法
- 为web.config写入数据库连接字符串的方法
- 为web.config写入数据库连接字符串的方法
- 为web.config写入数据库连接字符串的方法
- 为web.config写入数据库连接字符串的方法
- 保存(Access)数据库连接字符串的两种方法web.config
- 动态修改Web.config中数据库连接字符串的方法
- 获得web.config中数据库连接字符串的2种方法
- 获取web.config中数据库连接字符串的2种方法
- Web.config数据库连接字符串
- 获取WEB.config的数据库连接字符串
- web.config connectionStrings 数据库连接字符串的解释
- web.config connectionStrings 数据库连接字符串的解释
- web.config的数据库连接字符串进行加密
- web.config connectionStrings 数据库连接字符串的解释
- web.config connectionStrings 数据库连接字符串的解释
- web.config connectionStrings 数据库连接字符串的解释
- web.config connectionStrings 数据库连接字符串的解释
- 判断一个DW中是否有未保存的数据
- SSIS 的数数据导入问题
- 彻底解决Java的字符编码问题[00原创]
- SVN 配置方法
- asp.net中获取客户端ip地址的两种方法
- 为web.config写入数据库连接字符串的方法
- 如何设置网页关键字?(转)
- 用Debug函数实现API函数的跟踪
- spring开发参考手册
- 使用 LumiSoft.Net.POP3.Client 接收邮件
- Abstract class versus Interface
- 学好英语的20个经典要诀
- 字符串切割
- 致命的"this is not my project"