取得connectionStrings属性
取得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;
}
{
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");
}
{
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");
}
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· .NET Core 托管堆内存泄露/CPU异常的常见思路
· PostgreSQL 和 SQL Server 在统计信息维护中的关键差异
· C++代码改造为UTF-8编码问题的总结
· DeepSeek 解答了困扰我五年的技术问题
· 清华大学推出第四讲使用 DeepSeek + DeepResearch 让科研像聊天一样简单!
· 推荐几款开源且免费的 .NET MAUI 组件库
· 实操Deepseek接入个人知识库
· 易语言 —— 开山篇
· 【全网最全教程】使用最强DeepSeekR1+联网的火山引擎,没有生成长度限制,DeepSeek本体