This is a problem plagued me for several days, first look at the error message
Code:
private static string connectionString = ConfigurationManager.ConnectionStrings["connstr"].ConnectionString;
Profiles
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add name="connstr" connectionString="server=localhost;port=3306;user=root;password=123456;database=test"/>
</connectionStrings>
</configuration>
At first I thought it was the connection string, and then use the connection string directly public static string connectionString = "server=localhost;port=3306;user=root;password=123456;database=test";
so there is no problem
See a bit connectionString returned as null
is not a configuration file format or method of reading problems
then put into a configuration file
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="connstr" value="server=localhost;port=3306;user=root;password=123456;database=test"/>
</appSettings>
</configuration>
Reading method private static string connectionString = ConfigurationSettings.AppSettings[
so although it is not being given to the connection string read or null
So experienced a number of Baidu Google, see a problem, there are two main
- Problems connected string
server=localhost;port=3306;uid=root;pwd=123456;database=test
username changed into uid password pwd - File location
down on the ui layer project