Bug #56097 MySQL .NET Connector 6.3.3 does not successfully add a data connection in VS2010
Submitted: 18 Aug 2010 20:21 Modified: 19 Aug 2010 2:25
Reporter: Jim Munafo Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / NET Severity:S2 (Serious)
Version:6.3.3 OS:Windows (7 x64)
Assigned to: CPU Architecture:Any
Tags: Data Connection, fail, visual studio 2010, vs2010

[18 Aug 2010 20:21] Jim Munafo
Description:
I have MySQL Server 5.1 running in a remote VMWare server located on my development network.  I can connect to it just fine using MySQL workbench, and everything works great.

I am developing a solution in MSFT Visual Studio 2010 on Windows 7 64-bit and I am unable to successfully add a Data Connection to my VMWare MySQL server.  I know that all of the credentials are fine, and that I have the name of the server correct (I've also tried the IP address with no success).

Anyway, whenever I test the connection within VS2010 it always times out unsuccessfully.  I would expect the data connection to be setup properly.

Thank you.
-- Jim

How to repeat:
- Setup a remote MSFT Server 2003 box.
- Install VMWare on the box
- Setup a MSFT Server 2008 Enterprise VMWare image on the box (x64).
- Install MySQL Server 5.1 in the VMWare image.
- On another development machine running Windows 7 x64, connect to the MySQL server using MySQL workbench
- Install Visual Studio 2010 on the development machine
- Install MySQL connector on the development machine
- Try to add a data connection to the MySQL server within VS2010 on the development machine.

Suggested fix:
- Create a connection properly.
[18 Aug 2010 20:27] Vladislav Vaintroub
jim, if you're getting this timeout, something else will be wrong.
e.g port number, it is not default, you have to "advanced" edit this connection to change the port.

Also, try to connecting first from test application.

using (MySqlConnection conn = new MySqlConnection(connectionString))
{
  //do something;
}

just to check if that works.
[18 Aug 2010 20:57] Jim Munafo
Hey Vladislav,

Thanks for the quick response.  I checked the settings again in the advanced button, and the port number is correct as well (it was set to 3306).

I also tried setting up a test client like you suggested.  Here's my code:
var lConnectionString = 
  "Server=172.1.0.29; Port=3306; Database=main; Uid=myuser; Pwd=mypassword";

try
{
  using (MySqlConnection conn = new MySqlConnection(lConnectionString))
  {
    conn.Open();
    conn.Close();
  }
}
catch (Exception e)
{
  Console.Writeline(e.ToString());
}

The code above fails at the conn.Open() line with the exception:
A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.

I'm still confused why the MySQL workbench would work and this code would not.

Any other thoughts?

Thanks again,
-- Jim
[18 Aug 2010 23:19] Vladislav Vaintroub
Callstack of the exception would help you (and me) to understand the problem better
[18 Aug 2010 23:28] Vladislav Vaintroub
Here is the stock code used to connect to some server on some port.
Connector/NET is not exactly the same, but if the below code works, and Connector/NET fails, then Connector/NET has a problem, unless  it takes more than "Connect Timeout" (15 seconds default) to connect to the server (in which case probably server has a problem). Otherwise, .NET has a problem..
   
     private static Socket ConnectSocket(string server, int port)
        {
            Socket s = null;
            IPHostEntry hostEntry = null;

            // Get host related information.
            hostEntry = Dns.GetHostEntry(server);

            // Loop through the AddressList to obtain the supported AddressFamily. This is to avoid
            // an exception that occurs when the host IP Address is not compatible with the address family
            // (typical in the IPv6 case).
            foreach (IPAddress address in hostEntry.AddressList)
            {
                IPEndPoint ipe = new IPEndPoint(address, port);
                Socket tempSocket =
                    new Socket(ipe.AddressFamily, SocketType.Stream, ProtocolType.Tcp);

                tempSocket.Connect(ipe);

                if (tempSocket.Connected)
                {
                    s = tempSocket;
                    break;
                }
                else
                {
                    continue;
                }
            }
            return s;
        }
[18 Aug 2010 23:31] Vladislav Vaintroub
And, do not try the below code too often, in case it works :) 

Server will try to detect Dos attacks if sockets connect and do nothing, after several attempts you'd need to execute "mysqladmin flush-hosts" to unblock your client machine.
[18 Aug 2010 23:35] Jim Munafo
Ha.  Thanks, I'll try your socket code in a sec.  Here's the stack trace for the exception:

StackTrace:

at MyNetworkStream.HandleOrRethrowException(Exception e)
at MyNetworkStream.Read(Byte[] buffer, Int32 offset, Int32 count)
at MySql.Data.MySqlClient.TimedStream.Read(Byte[] buffer, Int32 offset, Int32 count)
at System.IO.BufferedStream.Read(Byte[] array, Int32 offset, Int32 count)
at MySql.Data.MySqlClient.MySqlStream.ReadFully(Stream stream, Byte[] buffer, Int32offset, Int32 count)
at MySql.Data.MySqlClient.MySqlStream.LoadPacket()
at MySql.Data.MySqlClient.MySqlStream.ReadPacket()
at MySql.Data.MySqlClient.NativeDriver.Open()
at MySql.Data.MySqlClient.Driver.Open()
at MySql.Data.MySqlClient.Driver.Create(MySqlConnectionStringBuilder settings)
at MySql.Data.MySqlClient.MySqlPool.GetPooledConnection()
at MySql.Data.MySqlClient.MySqlPool.TryToGetDriver()
at MySql.Data.MySqlClient.MySqlPool.GetConnection()
at MySql.Data.MySqlClient.MySqlConnection.Open()
at testClient.testClient.Main(String[] args) in C:\test\testClient\testClient.cs:line 23
[18 Aug 2010 23:44] Jim Munafo
Hey Vladislav,

I tried your Socket code, and it worked out fine.  I'm going to install VS2010 on an XP SP3 x86 dev machine and see if the code works on that.

I'll let you know what I find.  Thanks.
-- Jim
[19 Aug 2010 1:40] Jim Munafo
Well, on my Windows 7 (x64) host machine, I setup a Windows XP SP3 (x86) virtualized machine and tried the following code in the virtualized machine:

var lConnectionString = 
  "Server=172.1.0.29; Port=3306; Database=main; Uid=myuser; Pwd=mypassword;";

try
{
  using (MySqlConnection conn = new MySqlConnection(lConnectionString))
  {
    conn.Open();
    conn.Close();
  }
}
catch (Exception e)
{
  Console.Writeline(e.ToString());
}

Unfortunately, it still didn't work.  

Any ideas?

Thanks.
-- Jim
[19 Aug 2010 1:46] Jim Munafo
Wow ...

Sorry Vladislav.  Apparently I just have a POS server.  I increased the connection timeout to 60 and it finally connected using the test connection code.

Hrmm ...

I think the ball's in my court now.  Sorry for the trouble.

-- Jim
[19 Aug 2010 2:25] Vladislav Vaintroub
ok, as problem now fixed, I'm closing the bug