SHARE
TWEET

Untitled

a guest Aug 17th, 2018 88 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Get user and password from ConnectionStringSettings
  2. <connectionStrings>
  3. <add name="MyConString" connectionString="Data Source=(local);Initial Catalog=MyDatabase;Persist Security Info=True;User ID=MyUsername Password=MyPassword;Connect  providerName="System.Data.SqlClient"/>    
  4. </connectionStrings>
  5.    
  6. SqlConnectionStringBuilder builder =  new SqlConnectionStringBuilder("Your connection string");
  7. string password = builder.Password;
  8.    
  9. string connString = ConfigurationManager.ConnectionStrings["MyConString"].ConnectionString;
  10.    
  11. SqlConnectionStringBuilder con = new SqlConnectionStringBuilder(ConfigurationManager.ConnectionStrings["ConnString"].ConnectionString);
  12. string myUser = con.UserID;
  13. string myPass = con.Password;
  14.    
  15. var builder = new SqlConnectionStringBuilder(ConfigurationManager.ConnectionStrings["MyConString"].ConnectionString)
  16. var user = builder.UserID;
  17. var password = builder.Password;
  18.    
  19. SqlConnectionStringBuilder yourconn = new SqlConnectionStringBuilder(ConfigurationManager.ConnectionStrings["ConnString"].ConnectionString);
  20. string password = yourconn.Password;
  21.    
  22. var connString = ConfigurationManager.ConnectionStrings["MyConString"].ConnectionString;
  23. var tokens = connString.Split(';');
  24.  
  25. string userId;
  26. string password;
  27.  
  28. for(var i = 0;  i < tokens.Length; i++) {
  29.     var token = tokens[i];
  30.     if(token.StartsWith("User ID"))
  31.         userId = token.Substring(token.IndexOf("=") + 1);
  32.  
  33.     if(token.StartsWith("Password"))
  34.         password = token.Substring(token.IndexOf("=") + 1);
  35. }
  36.    
  37. string connectionString = ConfigurationManager.ConnectionStrings["MyConString"].ConnectionString;
  38. var tokens = connectionString.Split(';').Select(n => n.Split('=');
  39. string userId = tokens.First(n => n[0].Equals("User ID").Select(n => n[1]);
  40. string password = tokens.First(n => n[0].Equals("Password").Select(n => n[1]);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top