出于某种原因,我在解析web.config文件中的连接字符串时有一段时间.
我已经获得了connectionString,但我正在尝试获取所有的值,例如
>数据源
>初始目录
>用户名
>等……
连接字符串如下所示:
Data Source=db.sample.com;user
id=sample-user;password=sample-password;Initial
Catalog=sample-catalog;
使用System.Data.Common.DbConnectionStringBuilder
原文链接:https://www.f2er.com/regex/356802.html$sb = New-Object System.Data.Common.DbConnectionStringBuilder $sb.set_ConnectionString('Data Source=db.sample.com;user id=sample-user;password=sample-password;Initial Catalog=sample-catalog;') $sb
输出:
Key Value --- ----- data source db.sample.com user id sample-user password sample-password initial catalog sample-catalog
另请参阅更多详细信息:DbConnectionStringBuilder does not parse when used in PowerShell
(这就是使用这个有趣的语法$sb.set_ConnectionString(…)而不是$sb.ConnectionString = …)的原因.