日期:2014-05-17  浏览次数:20627 次

asp。net连接mysql数据库字符串连接不上
XML code
<add key="SqlString" value=" Server=127.0.0.1;Database=dbtraffic;Uid=root;Pwd=1"/>

连接不上在网上找的一些例子都不行,这个连接没有提示错误。就是不显示数据在网页上
C# code
string con = ConfigurationManager.ConnectionStrings["SqlString"].ConnectionString;
                using (MySqlConnection cn = new MySqlConnection(con))
这样连接不上



 
C# code
  using (MySqlConnection cn = new MySqlConnection("server=localhost;user id=root;password=1;database=dbtraffic"))


这样就可以连接的上,求大神

------解决方案--------------------
string con =System.Configuration.ConfigurationManager.AppSettings["SqlString"];
------解决方案--------------------
举例:

MySql.Data.MySqlClient.MySqlConnection conn = new MySqlConnection();

conn.ConnectionString = ConfigurationManager.ConnectionStrings["dlxjConnectionString"].ConnectionString;



------解决方案--------------------
注意connectionStrings和appSettings配置节的区别

C# code

<appSettings>
   <add key="SqlString" value=" Server=localhost;Database=dbtraffic;Uid=root;Pwd=1"/>
</appSettings>

string con = ConfigurationManager.AppSettings["SqlString"];
using (MySqlConnection cn = new MySqlConnection(con))
{
    //...
}