0

I have a SQL connection string being stored in the web.config.

How can I pull items like server name, username, password... inside of C# ASP.Net code?

3 Answers 3

6

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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

Here is a link to the msdn documentation.

Enjoy!

Comments

0

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.