webressurs
asked on
Connectionstring App.config / App.Settings
I have a strage problem. When trying to read the connectionstring from App.config (System.Configuration.Conf igurationM anager.Con nectionStr ings["Conn ectionStri ng"].Conne ctionStrin g) I get Null Reference Exception even if the connection string is correct written in the App.config file. I have also set correct reference to the System.configuration.dll. When I put the connectionsting in a App.settings file it works without problems. I have tried everything and is going nuts. What can cause this problem?
Please see attached code :)
Please see attached code :)
-----------------------------
App.config
-----------------------------
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections></configSections>
<connectionStrings>
<add name="ConnectionString" connectionString="Data Source=localhost;Initial Catalog=Rank;Persist Security Info=True;User ID=Rank;Password=Password;"
providerName="System.Data.SqlClient" />
<add name="Rank.App.ConnectionString" connectionString="Data Source=localhost;Initial Catalog=Rank;Persist Security Info=True;User ID=Rank;Password=Password;" />
</connectionStrings>
</configuration>
namespace Rank
{
public class Common
{
public class Data
{
public static string ConnectionString
{
get
{
//THIS DONT WORK:
//return System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
//THIS WORK PERFECT:
return App.Default.ConnectionString.ToString();
}
}
}
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.