https://bugzilla.novell.com/show_bug.cgi?id=407208
Summary: Mono.Data.Tds.Protocol.TdsComm fails with 'No such host is known' Product: Mono: Class Libraries Version: SVN Platform: x86 OS/Version: Linux Status: NEW Severity: Major Priority: P5 - None Component: Sys.Data.SqlClient AssignedTo: mono-bugs@lists.ximian.com ReportedBy: [EMAIL PROTECTED] QAContact: mono-bugs@lists.ximian.com Found By: --- Created an attachment (id=226522) --> (https://bugzilla.novell.com/attachment.cgi?id=226522) Proposed patch that uses IPAddress.TryParse to check for an IP before trying Dns.GetHostEntry There is an issue in the TdsComm constructor when the DNS server is configured poorly, because it uses Dns.GetHostEntry(). The problem occurs when the DNS server is able to reverse-lookup the name for an IP address, but is not able to look up the IP for that hostname. Calling Dns.GetHostEntry() on an IP in this situation fails with 'No such host is known' - this happens with Mono and in MS.Net. When using System.Data.SqlClient.SqlConnection in Mono to open a connection to a database with the "Data Source" element in the connection string set to an IP, becuase it uses Dns.GetHostEntry(), the connection can fail with 'No such host is known' when it should connect to the IP. In MS.Net it works. This only happens when using the .NET 2.0 version of TdsComm - when compiling with .NET 1.0 (mcs instead of gmcs), the connection also works. I can't think of any reason to use Dns.GetHostEntry() on an IP address when connecting, so maybe the code in TdsComm.cs should try to parse the IP and connect directly to it when using .NET 2.0 instead of calling Dns.GetHostEntry. I'll attach some reproduction code, but reproducing requires setting up a DNS server with a bogus reverse lookup entry. In my case, I set up an entry for 10.190.99.1 to resolve to 'hello.bobscratcher.com', but didn't add an address entry for 'hello.bobscratcher.com' to resolve back to the IP: [EMAIL PROTECTED] mono_test]$ nslookup 10.190.99.1 1.99.190.10.in-addr.arpa name = hello.bobscratcher.com. [EMAIL PROTECTED] mono_test]$ nslookup hello.bobscratcher.com ** server can't find hello.bobscratcher.com: NXDOMAIN This IP address doesn't actually have a host living on it, but it works to illustrate the bug. The test code is: ------------------------ using System; using System.Data; using System.Data.SqlClient; namespace hostentrytest { class Program { static void Main (string[] args) { using(SqlConnection conn = new SqlConnection("Data Source=10.190.99.1;Network Library=DBMSSOCN;Initial Catalog=master;Pooling=False;Trusted_Connection=False;User ID=hello;Password=hello")) { try { conn.Open(); } catch (Exception e) { Console.WriteLine("{0}", e); } } } } } ------------------------ Compiling this code with mcs and running results in this error in Mono, which is expected: debacle:~/monotest$ mcs ./test.cs -r:System.Data.dll debacle:~/monotest$ mono ./test.exe System.Data.SqlClient.SqlException: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. ---> Mono.Data.Tds.Protocol.TdsTimeoutException: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. Compiling the code with gmcs and running results in the 'No such host is known' error, which is not expected: debacle:~/monotest$ gmcs ./test.cs -r:System.Data.dll debacle:~/monotest$ mono ./test.exe System.Data.SqlClient.SqlException: Server does not exist or connection refused. ---> Mono.Data.Tds.Protocol.TdsInternalException: Server does not exist or connection refused. ---> System.Net.Sockets.SocketException: No such host is known at System.Net.Dns.hostent_to_IPHostEntry (System.String h_name, System.String[] h_aliases, System.String[] h_addrlist) [0x00000] at System.Net.Dns.GetHostByAddressFromString (System.String address, Boolean parse) [0x00000] Compiling the code with Visual Studio 2005 and .NET 2.0 results in the expected error: C:\proj\sqltest\sqltest\bin\Debug>sqltest.exe System.Data.SqlClient.SqlException: An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: TCP Provider, error: 0 - 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.) A proposed patch is attached. -- Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- You are the QA contact for the bug. You are the assignee for the bug. _______________________________________________ mono-bugs maillist - mono-bugs@lists.ximian.com http://lists.ximian.com/mailman/listinfo/mono-bugs