20070702 winxp win2003 MySql.Data.MySqlClient.MySqlException
http://www.yippeesoft.com

MySql.Data.MySqlClient.MySqlException: Unable to connect to any of the specified MySQL hosts

简单的代码:
 private MySqlConnection conn = new MySqlConnection(
                "server=111.111.111;user id=root; password=123; database=123; pooling=false;charset=utf8");
        MySqlCommand cmd=new MySqlCommand();
       
            conn.Open();

原来在WINXP下OK,结果WIN2003下出现
************** 异常文本 **************
MySql.Data.MySqlClient.MySqlException: Unable to connect to any of the specified MySQL hosts —> System.Net.Sockets.SocketException: 不知道这样的主机。
   在 System.Net.Dns.GetAddrInfo(String name)
   在 System.Net.Dns.InternalGetHostByAddress(IPAddress address, Boolean includeIPv6, Boolean throwOnFailure)
   在 System.Net.Dns.GetHostEntry(String hostNameOrAddress)
   在 MySql.Data.Common.StreamCreator.GetStream(UInt32 timeOut)
   在 MySql.Data.MySqlClient.NativeDriver.Open()

连接本机OK。用PHPMYADMIN连接远端OK

错误出现:
 else
    &leftsign;
#if NET20
     IPHostEntry ipHE = Dns.GetHostEntry(dnsHosts[index]);

************** 异常文本 **************
System.Net.Sockets.SocketException: 不知道这样的主机。
   在 System.Net.Dns.GetAddrInfo(String name)
   在 System.Net.Dns.InternalGetHostByAddress(IPAddress address, Boolean includeIPv6, Boolean throwOnFailure)
   在 System.Net.Dns.GetHostEntry(String hostNameOrAddress)

WSAHOST_NOT_FOUND  
      (11001)  
      Host   not   found.  
      No   such   host   is   known.   The   name   is   not   an   official   hostname   or   alias,   or   it   cannot   be   found   in   the   database(s)   being   queried.   This   error   may   also   be   returned   for   protocol   and   service   queries,   and   means   the   specified   name   could   not   be   found   in   the   relevant   database.    
改用:
GetHostByName 就OK

真是莫名其妙~

Using the ado.net connector in visual basic .net 2002 to interact with mysql
4.0.17 I\’m using the connection string

"datasource=localhost;database=test;uid=myuser;password=mypass;"

it gives the exception "Unable to connect to any of the specified Mysql hosts"
when I try to open the connection

I am able to connect to the database using a web interface and an odbc interface
but am unable to connect to it using the .net connector.

How to repeat:
myConnection = New
ByteFX.Data.MySqlClient.MySqlConnection("datasource=localhost;database=test;uid=
tim;password=mypass;")
myConnection.Open()

My analysis:

Connection string:
Host=localhost;Database=dbname;User Id=myuser;Password=pass

What I see is that StreamCreator.GetStream() gets the IP address(es) of the host
using:

  IPHostEntry ipHE = Dns.GetHostEntry(dnsHosts[index]);
(line 73)

On my system IPv6 networking is enabled, so the resulting address list contains
IPv6 addresses and IPv4 address is the last of the list. Please note that I\’m
*not* trying to connect to a v6 address.
Afterwards StreamCreator.GetStream() pass down each address to
CreateSocketStream() until one is successful. Problem is that inside
CreateSocketStream() the socket is created using AF "InterNetwork" (lines
131-133); BeginConnect() is called on this socket using a v6 address and throws
an exception. The outer loop cannot handle the exception which propagates back
and prevent any connection.

1.0.7 does not exhibit this behaviour.

How to repeat:
string connStr = "Host=localhost;Database=dbname;User Id=myuser;Password=pass"
MySqlConnection conn = new MySqlConnection(connStr);
conn.Open();

IPv6 networking must be enabled.

Suggested fix:
Skip any IPv6 address returned by GetHostEntry. I\’ve modified the loop in
StreamCreator.GetStream() in this way:

foreach (IPAddress address in ipHE.AddressList)
&leftsign;
 /* Skip IPv6 addresses */
 if (address.AddressFamily == AddressFamily.InterNetworkV6)
  continue;
 stream = CreateSocketStream(address, port, false);
 if (stream != null)
  break;
&rightsign;

原创文章,转载请注明: 转载自YippeeSoft开心软件

本文链接地址: 20070702 winxp win2003 MySql.Data.MySqlClient.MySqlException

历史博文

标签:, , , , , ,