zoukankan
html css js c++ java
为web.config写入数据库连接字符串的方法
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();
}
查看全文
相关阅读:
「网络流 24 题」魔术球
「网络流 24 题」圆桌聚餐
「网络流 24 题」最小路径覆盖
「网络流 24 题」太空飞行计划
「网络流 24 题」搭配飞行员
「网络流 24 题」负载平衡
「网络流 24 题」数字梯形
餐巾计划问题
让Double类型完整显示,不用科学计数法显示E
kotlin新工程
原文地址:https://www.cnblogs.com/Clingingboy/p/388288.html
最新文章
CSP2019 S2滚粗记
BZOJ2591/LG3047 「USACO12FEB」Nearby Cows 换根树形DP
[BZOJ4826][HNOI2017]影魔 可持久化线段树
[BZOJ4026]dC Loves Number Theory 欧拉函数+线段树
[UOJ#334][NOIP2017]列队 平衡树/线段树/树状数组
BSGS & exBSGS
逆元
树状数组
线段树
马拉车(Manachar)——最长回文串
热门文章
折半枚举
2019牛客暑期多校训练营(第九场) Knapsack Cryptosystem
最大公约数&最小公倍数
扩展欧几里德|模线性方程
欧拉函数|降幂
素数筛选
poj 2689 Prime Distance
2019牛客暑期多校训练营(第三场) Planting Trees
单调栈&单调队列
「网络流 24 题」最长递增子序列
Copyright © 2011-2022 走看看