Haz 18 2009

Retrieve individual data from ConnectionString

Category: ASP.NETLatif @ 18:04

   If you want to retrieve data(password ,UserID,DataSource,InitialCatalog) , you can use SqlConnectionStringBuilder (From .NET Framework 2.0, there is System.Data.Common.DbConnectionStringBuilder  and its derived classes (SqlConnectionStringBuilder for SqlServer))

string connectionString = WebConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString;
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(connectionString);

string password = builder.Password;
string username = builder.UserID;
string dataSource = builder.DataSource;
string initialCatalog = builder.InitialCatalog;


Tags: ,