我对MySQL连接有一个奇怪的问题。我的环境是
操作系统 - Microsoft Windows Home Basic
IDE - SharpDevelop 4.3.3.9663MySQL服务器 - 5.5
MySQL连接器 - 6.8.3
我创建了一个示例程序,它连接到我机器中的MySQL服务器。
using System;
using MySql.Data.MySqlClient;
namespace TestBed
{
class Program
{
private static MySql.Data.MySqlClient.MySqlConnection conn;
public static void Main(string[] args)
{
Console.WriteLine("Hello World!");
connect();
Console.Write("Press any key to continue . . . ");
Console.ReadKey(true);
}
public static void connect()
{
string myConnectionString;
//myConnectionString = "Server=localhost; Port=3306; Database=test; Uid=root; Pwd=Welcome01;"; //works fine in rel mode
myConnectionString = "Server=127.0.0.1; Port=3306; Database=test; Uid=root; Pwd=Welcome01;";
try
{
conn = new MySql.Data.MySqlClient.MySqlConnection(myConnectionString);
conn.Open();
Console.WriteLine("opened");
}
catch (MySql.Data.MySqlClient.MySqlException ex)
{
Console.WriteLine(ex.Message);
}
}
}
}
我在开始时遇到了以下错误。
MySql.Data.MySqlClient.MySqlException: Unable to connect to any of the specified MySQL hosts.
at System.Void MySql.Data.MySqlClient.NativeDriver.Open()
at System.Void MySql.Data.MySqlClient.Driver.Open()
at static Driver MySql.Data.MySqlClient.Driver.Create(MySql.Data.MySqlClient.MySqlConnectionStringBuilder settings)
at Driver MySql.Data.MySqlClient.MySqlPool.CreateNewPooledConnection()
at Driver MySql.Data.MySqlClient.MySqlPool.GetPooledConnection()
at Driver MySql.Data.MySqlClient.MySqlPool.TryToGetDriver()
at Driver MySql.Data.MySqlClient.MySqlPool.GetConnection()
at System.Void MySql.Data.MySqlClient.MySqlConnection.Open()
at static System.Void TestBed.Program.method() in ...\TestBed\Program.cs:line 36
at static System.Void TestBed.Program.Main(System.String[] args) in ...\Program.cs:line 19
我从此链接(Cant connect to MySQL when using Debug mode)获得了提示,并尝试使用发布模式。令人惊讶的是它能够打开连接!
我对它进行了更多分析并找到了以下内容。
我不确定我做错了什么,或者它是MySQL或SharpDevelop的错误。有没有人遇到过这种问题?如果可能的话,有人请对此有所了解吗?
谢谢, Ganesh Periasamy
答案 0 :(得分:0)
试试这个..
"Persist Security Info=False;server=127.0.0.1;database=xx;uid=yy;password=zz"
答案 1 :(得分:0)
好的。据报道,这是SharpDevelop Debugger(http://community.sharpdevelop.net/forums/t/16473.aspx)中的一个错误,但SharpDevelop团队在一年内没有回复!我将与他们一起跟进并尝试更新此帖子,以防万一我得到。