MySQL服务器连接不能在c# .net中工作

本文关键字:net 工作 服务器 连接 不能 MySQL | 更新日期: 2023-09-27 17:50:23

配置文件:

<connectionStrings>
 <add name="ApplicationServices" connectionString="Data Source=localhost;Initial             Catalog=uday;User Id=root;Password=mysql@niperhyd" providerName="MySql.Data.MySqlClient"/>
</connectionStrings>

string strConnString = ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString;
MySqlConnection connection = new MySqlConnection(strConnString);
connection.Open();
lblMsg.Text = "connection established";
connection.Close();

MySQL服务器连接不能在c# .net中工作

From MySQL ConnectionString

1。你需要用Database代替Initial Catalog

2。您需要使用Server而不是Data Source

试试这个:

<add name="ApplicationServices" connectionString="Server=localhost;Database=uday;
    User Id=root;Password=mysql@niperhyd" providerName="MySql.Data.MySqlClient"/>

试试这个

<add name="connstring" connectionString="Server=localhost;Database=uday;Persist Security Info=True;User Id=root;Password=mysql@niperhyd" providerName="MySql.Data.MySqlClient"/>