大家好,又见面了,我是你们的朋友全栈君。
取得Web config文件连接数据库字符各个属性。
代码
public
string
GetConnectionValue(
string
Keyword,
string
connectionString)
{
string
[] aa
=
Keyword.Split(
‘
,
‘
);
string
[] bb
=
connectionString.Split(
‘
;
‘
);
string
strTempValue
=
string
.Empty;
foreach
(
string
b
in
bb)
{
foreach
(
string
a
in
aa)
{
if
(b.IndexOf(
“
=
“
)
<
0
)
continue
;
if
(b.StartsWith(a, StringComparison.OrdinalIgnoreCase))
strTempValue
=
b.Substring(b.IndexOf(
“
=
“
)
+
1
);
}
}
return
strTempValue;
}
代码
public
string
GetServerName()
{
string
key
=
“
Data Source,Server,Address,Addr,Network Address
“
;
return
GetConnectionValue(key);
}
public
string
GetDataBaseName()
{
string
key
=
“
Initial Catalog,Database
“
;
return
GetConnectionValue(key);
}
public
string
GetPassword()
{
string
key
=
“
Password,Pwd
“
;
return
GetConnectionValue(key);
}
public
string
GetUserId()
{
string
key
=
“
User ID,uid
“
;
return
GetConnectionValue(key);
}
public
string
GetPacketSize()
{
string
key
=
“
Packet Size
“
;
return
GetConnectionValue(key);
}
public
string
GetPooling()
{
string
key
=
“
Pooling
“
;
return
GetConnectionValue(key);
}
public
string
GetMaxPoolSize()
{
string
key
=
“
Max Pool Size
“
;
return
GetConnectionValue(key);
}
public
string
GetTrustedSecurity()
{
string
key
=
“
Integrated Security,Trusted_Connection
“
;
return
GetConnectionValue(key);
}
public
bool
IsTrustedSecurityConnection()
{
string
sScty
=
GetTrustedSecurity();
return
(sScty
==
“
SSPI
“
||
sScty
==
“
True
“
);
}
public
bool
IsAtLocalMachine()
{
string
sName
=
GetServerName();
return
(sName
==
“
127.0.0.1
“
||
sName
==
“
localhost
“
);
}
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/143292.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...