C# 通过 connectionString 获取 DataBase 名字
connectionString有可能如下两种,DataBase的位置可能在最后也可能在中间
<add key="connectionString" value="server=.;UID=kan_li;PWD=197001;Database=SPAdmin"/>
<add key="connectionString" value="server=.;Database=SPAdmin;UID=kan_li;PWD=197001"/>
怎么正确的取到当前的Database的值
[解决办法]
string con = "server=.;UID=kan_li;Database=SPAdmin;PWD=197001;";
Regex reg = new Regex(@"Database=(?<Database>[\s\S]*?)(;
[解决办法]
$)", RegexOptions.IgnoreCase);
Match mc = reg.Match(con);
if (mc.Success)
{
Response.Write(mc.Groups["Database"].Value);
}
Response.End();