[Mono-bugs] [Bug 407208] New: Mono.Data.Tds.Protocol.TdsComm fails with ' No such host is known'

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Tue Jul 8 12:29:12 EDT 2008


           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 at lists.ximian.com
        ReportedBy: jlarimer at gmail.com
         QAContact: mono-bugs at 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

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 to resolve to 'hello.bobscratcher.com', but didn't add an address
entry for 'hello.bobscratcher.com' to resolve back to the IP:

  [jlarimer at f7-ccm-dev mono_test]$ nslookup        name = hello.bobscratcher.com.

  [jlarimer at f7-ccm-dev 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=;Network Library=DBMSSOCN;Initial
ID=hello;Password=hello")) {
                                try {
                                } 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

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

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.

More information about the mono-bugs mailing list