开发者

Powershell regex for connectionStrings?

For some reason I'm having a brutal time parsing the conn开发者_如何转开发ection string in the web.config file.

I've already gotten connectionString but I'm trying to get all the values such as the

  • Data Source
  • Initial Catalog
  • Username
  • etc...

The connection string looks like:

Data Source=db.sample.com;user id=sample-user;password=sample-password;Initial Catalog=sample-catalog;


Use System.Data.Common.DbConnectionStringBuilder

$sb = New-Object System.Data.Common.DbConnectionStringBuilder

# Attempting to set the ConnectionString property directly won't work, see below
$sb.set_ConnectionString('Data Source=db.sample.com;user id=sample-user;password=sample-password;Initial Catalog=sample-catalog;')

$sb

Output:

Key             Value          
---             -----          
data source     db.sample.com  
user id         sample-user    
password        sample-password
initial catalog sample-catalog 

See also for more details: DbConnectionStringBuilder does not parse when used in PowerShell

(That is why this funny syntax $sb.set_ConnectionString(...) is used instead of $sb.ConnectionString = ...).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜