12/14/2011

Adding Connection String and keys in web.config

In order to add a connectionstring to web.config:
< connectionStrings >
< add name="myconn" connectionString="Data Source=*****;Initial Catalog=Excentive;User ID=*****;Password=*****;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" / >
< / connectionStrings >

In order to get connection string in a cs file:
System.Configuration.ConfigurationManager.ConnectionStrings["myconn"].ConnectionString)

If you want to add key to web.config:
< appSettings >
< add key="ServerURL" value="my_url" / >
< / appSettings >

When you want to call it in your cs file:
ConfigurationManager.AppSettings["ServerURL"]



No comments:

Post a Comment