Alright. This has been reported as a bug in SharpDevelop Debugger (http://community.sharpdevelop.net/forums/t/16473.aspx) but no responses from SharpDevelop team for about an year! I will follow up this with them and try to update this thread, in case I get any.
MySQL connection fails in debug mode
-
11-10-2022 - |
Question
I have a strange issue with MySQL connectivity. My environment is
OS - Microsoft Windows Home Basic
IDE - SharpDevelop 4.3.3.9663MySQL Server - 5.5
MySQL Connector - 6.8.3
I created a sample program that connects to the MySQL server in my machine.
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);
}
}
}
}
I was getting the below error in the beginning.
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
I got a hint from this link (Cant connect to MySQL when using Debug mode) and tried with Release mode. Surprisingly it was able to open the connection!
I analyzed it a bit more and found the below things.
- It throws the error only if I use Debug->Step over (using F10 keys to debug step by step)!
- If I just start the app in Debug mode, it connects.
- I am able to step break points above and below the "connect()" method
- I can also use step over (with F10 key) to debug other parts of the application, but if I use step over into this method, it takes a long time and throws the same error.
I am not sure whether I am doing anything wrong, or it is a bug with MySQL or SharpDevelop. Has anyone faced this kind of issue? If possible, someone please throw some light on this?
Thanks, Ganesh Periasamy
Solution 2
OTHER TIPS
try this..
"Persist Security Info=False;server=127.0.0.1;database=xx;uid=yy;password=zz"