解析连接字符串
是否有标准库或代码片段可以使用这样的连接字符串获取值?
string connstr = "DataServiceUrl=http://localhost/foo;" +
"RemoteServerConnection={server=http://localhost/foo2;interface=0.0.0.0;};" +
"publisherport=1234;StatisticsURL=http://localhost/foo3";
整个内部连接属性有点将其置于循环中。我想根据键获取特定值。
这是我使用的约翰发布的答案:
System.Data.Odbc.OdbcConnectionStringBuilder builder = new System.Data.Odbc.OdbcConnectionStringBuilder();
builder.ConnectionString = this.ConnectionString;
MessageBox.Show(builder["RemoteServerConnection"]);
Is there a standard library or code snippet to get a value with a connection string like this?
string connstr = "DataServiceUrl=http://localhost/foo;" +
"RemoteServerConnection={server=http://localhost/foo2;interface=0.0.0.0;};" +
"publisherport=1234;StatisticsURL=http://localhost/foo3";
The whole inner connection property is kind of throwing this in a loop. I'd like to get specific values based on a key.
Here was the answer posted by John I used:
System.Data.Odbc.OdbcConnectionStringBuilder builder = new System.Data.Odbc.OdbcConnectionStringBuilder();
builder.ConnectionString = this.ConnectionString;
MessageBox.Show(builder["RemoteServerConnection"]);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将“
{
”和“}
”替换为(“
)即可解决问题:Replacing "
{
" and "}
" by ("
) does the trick: