I am using Visual Studio 2012 and I am building a web application in Framework 4.5.
I want to save my connection string in the web config and to read from there.
For some reason i cant read it.
The web config
<connectionStrings>
<add name="AdminConnection" connectionString="DataSource=10.0.0.20;InitialCatalog=MailDB;PersistSecurityInfo=True;UserID=s a;Password=********;"/>
The code
using System.Configuration;
string connectionString = System.Configuration.ConfigurationManager.AppSettings["AdminConnection"];
I am getting error on the configuration manager, and i tried all sort of variations.
Thank for all.
That’s not right. It’s stored in your
ConnectionStringsnot yourAppSettings. See the MSDN for How to: Read Connection Strings for more information.