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: | |
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
[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