第一次接触MySql,
.Net程序 链接字符串是这样写的
protected static string connectionString = "Server=localhost;User Id=root;Password=;Persist Security Info=True;Database=test";using (MySqlConnection connection = new MySqlConnection(connectionString))
{
using (MySqlCommand cmd = new MySqlCommand(SQLString, connection))
{
try
{
connection.Open();
int rows = cmd.ExecuteNonQuery();
return rows;
}
catch (Exception E)
{
connection.Close();
throw E;
}
}
}
每次connection.open()时就报错 Unable to connect to any of the specified MySQL hosts.
想知道是链接字符串的问题吗
我本地装的是ApmServ 和Sqlyog 没有单独安装MySql
求大神
.Net程序 链接字符串是这样写的
protected static string connectionString = "Server=localhost;User Id=root;Password=;Persist Security Info=True;Database=test";using (MySqlConnection connection = new MySqlConnection(connectionString))
{
using (MySqlCommand cmd = new MySqlCommand(SQLString, connection))
{
try
{
connection.Open();
int rows = cmd.ExecuteNonQuery();
return rows;
}
catch (Exception E)
{
connection.Close();
throw E;
}
}
}
每次connection.open()时就报错 Unable to connect to any of the specified MySQL hosts.
想知道是链接字符串的问题吗
我本地装的是ApmServ 和Sqlyog 没有单独安装MySql
求大神
<remove name="LocalMySqlServer"/>
<add name="LocalMySqlServer"
connectionString="Datasource=localhost;Database=users;uid=root;pwd=password;"
providerName="MySql.Data.MySqlClient"/>
</connectionStrings>
C# Example MySql.Data.MySqlClient.MySqlConnection conn;
string myConnectionString;myConnectionString = "server=127.0.0.1;uid=root;" +
"pwd=12345;database=test;";try
{
conn = new MySql.Data.MySqlClient.MySqlConnection();
conn.ConnectionString = myConnectionString;
conn.Open();
}
catch (MySql.Data.MySqlClient.MySqlException ex)
{
MessageBox.Show(ex.Message);
}参考一下MYSQL官方手册中的例子。