Currently I'm trying to connect SQL server DB from asp.net 4.5, keeping the connection string on Web.config file, using the following code to retrieve the connection string, but its retunr NULL value,
ConnectionStringSettings connString = ConfigurationManager.ConnectionStrings["ConString"]; SqlConnection Con = new SqlConnection(connString.ConnectionString);
the connection string in Web.Config is like
<connectionStrings> <add name="ConString" connectionString="Data Source=myservername;Initial Catalog=dbname;User ID=userid;Password=password;Integrated Security=True" xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/> </connectionStrings>
I'm not understanding why it return null value, previously, in 3.5 I have used the following code to get the connection string,
Con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["ConString"].ConnectionString);
it was working fine asp.net 3.5, but this also getting runtime error while using. Please let me know if I did any mistake.