tags:

views:

50

answers:

4

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?

A: 

Hi,

ConfigurationManager.ConnectionStrings("name of connection string in web.config")

Here is a link to the msdn documentation.

Enjoy!

Doug
A: 

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?

kacalapy
You should use the "add comment" link (instead of creating an answer) if you want to give feedback to an answer.
M4N
+3  A: 

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.

M4N
+1 - beat me to the answer and had code example
PHeiberg
A: 

Use a Regular Expression or the DbConnectionStringBuilder class in the BCL.

PHeiberg