Using the Web.Config to set up my SQL database connection string?

Viewed 129574

Can anyone help me out please? I'm confused.

I want to set up my connection string so I can just call it from my Web.Config file.

I need a way to call it from my code, please make a little example. :(

I also need help on setting up the Web.Config file.

I don't know what properties to use. Here's a screenshot of what my credentials are. I have no password set up for Windows. I'm really lost here.

alt text

8 Answers

Web.config file

<connectionStrings>
  <add name="MyConnectionString" connectionString="Data Source=SERGIO-DESKTOP\SQLEXPRESS;    Initial Catalog=YourDatabaseName;Integrated Security=True;"/>
</connectionStrings>

.cs file

System.Configuration.ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString;
Related