您的位置:首页 > 数据库

为web.config写入数据库连接字符串的方法

2006-04-29 09:06 513 查看
1.写入连接字符串

protected void Page_Load(object sender, EventArgs e)
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();
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: