获得从ConnectionStringSettings用户名和密码 [英] Get user and password from ConnectionStringSettings

查看:1483
本文介绍了获得从ConnectionStringSettings用户名和密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎样才能从这样的中的connectionString使用.NET函数在app.config的用户名和密码?



当然,我能读这个字符串并获得ID后的值=和密码=



 <&是connectionStrings GT; 
<添加名称=MyConString的connectionString =数据源=(本地);初始目录= MyDatabase的;坚持安全信息= TRUE;用户ID = MyUserName输入密码= MyPassword输入;连接的providerName =System.Data.SqlClient的/>
< /是connectionStrings>


解决方案

使用ConnectionBuilderClass

  SqlConnectionStringBuilder建设者=新SqlConnectionStringBuilder(您的连接字符串); 
串密码= builder.Password;



连同结果

 字符串CONNSTRING = ConfigurationManager.ConnectionStrings [MyConString]的ConnectionString; 

要实现这一点。


How can I get the user and password from such a connectionString in the app.config with a .NET function?

Of course I could read that string and get the value after the ID= and Password=.

<connectionStrings>
<add name="MyConString" connectionString="Data Source=(local);Initial Catalog=MyDatabase;Persist Security Info=True;User ID=MyUsername Password=MyPassword;Connect  providerName="System.Data.SqlClient"/>    
</connectionStrings>

解决方案

use the ConnectionBuilderClass

SqlConnectionStringBuilder builder =  new SqlConnectionStringBuilder("Your connection string");
string password = builder.Password;


together with the

string connString = ConfigurationManager.ConnectionStrings["MyConString"].ConnectionString;

to achieve this.

这篇关于获得从ConnectionStringSettings用户名和密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆