in case of the first one i.e
ConfigurationManager.ConnectionStrings["MyConnection"].ConnectionString
u have to put your connection string in web.config like
<appSettings>
<add key="MyConnection" value="Data Source=RITESH\SQLEXPRESS;Initial Catalog=Test1; Integrated Security=true"/>
</appSettings>
and its secure way to keep connection string in web config.
there should not be any issue og not getting connection this way.
==================================================================
Arun : I don't think that this is correct.What you specified is
ConfigurationManager.AppSettings["MyConnection"]
not
ConfigurationManager.ConnectionStrings["MyConnection"]
.
==================================================================