i have a sql connection string being stored in the web.config.
how can i pull items liek server name, username, password... insode of c# asp.net code?
i have a sql connection string being stored in the web.config.
how can i pull items liek server name, username, password... insode of c# asp.net code?
Hi,
ConfigurationManager.ConnectionStrings("name of connection string in web.config")
Here is a link to the msdn documentation.
Enjoy!
yes i got that, but how do i pull the username, server, password?
so: strUser = ConfigurationManager.ConnectionStrings("sqlcon").username();
same for password, and server...
how can i get the cvlaues within the con. string inside my asp.net code?
You can use the SqlConnectionStringBuilder for that:
var connectionString = GetConnectionString(); //e.g. use code shown in other answer
var builder = new SqlConnectionStringBuilder(connectionString);
var user = builder.UserID;
There's some sample code on this MSDN page.
Use a Regular Expression or the DbConnectionStringBuilder class in the BCL.