0

I have created a simple program to illustrate problem. I have a console application that should connect to a external SQL Server instance.

Locally I can connect to this host just fine (whether the be set to the IP address or the external URL that the server is associated with via DNS). When I copy the compiled version of the application over to a Ubuntu server with Mono installed and run the application using mono ConsoleApplication1.exe, I am presented with this error everytime:

System.Data.SqlClient.SqlException: Server does not exist or connection refused. at System.Data.SqlClient.SqlConnection.Open () <0x409d4e90 + 0x0053f> in :0 at ConsoleApplication1.Program.Main (System.String[] args) <0x409a7d50 + 0x00077> in :0 [ERROR] FATAL UNHANDLED EXCEPTION: System.Data.SqlClient.SqlException: Server does not exist or connection refused. at System.Data.SqlClient.SqlConnection.Open () <0x409d4e90 + 0x0053f> in :0 at ConsoleApplication1.Program.Main (System.String[] args) <0x409a7d50 + 0x00077> in :0

I have tried using a direct IP to the SQL Server instance and also the external URL (in place of below), which I know works locally running this application.

The code used to setup in the application:

App.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <connectionStrings>
    <add name="Test" connectionString="data source=<Host>\<Instance Name>, 1069;database=<Database Name>;user id=<User>;password=<Password>;multipleactiveresultsets=True;"/>
  </connectionStrings>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/>
  </startup>
</configuration>

C# Code

class Program
{
    static void Main(string[] args)
    {
        using (var connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Test"].ConnectionString))
        {
            connection.Open();
            Console.WriteLine("Connected");
        }
    }
}

Environment:

  • SQL Server: Windows 2012 DC with SQL Server 2014 Instance
  • Mono Environment: Ubuntu 16.04 running Latest Mono-Complete
  • .NET Version: 4.6.2 (also tried 4.5.2)

Update: I can confirm that using FreeTDS I can connect to the instance of SQL Server from the Ubuntu instance, so the problem seems isolated to running the application.

Jono_2007
  • 1,016
  • 3
  • 12
  • 23
  • Is any other software on your Ubuntu system able to connect? – Dai Nov 17 '16 at 22:57
  • Thus far I have verified the Ubuntu machine can telnet that host and that port and get a response, I'm going to try use something like free tds to see can establish a TSQL connection – Jono_2007 Nov 17 '16 at 23:09
  • Does your SQLServer log show the connection? Any error? – SushiHangover Nov 17 '16 at 23:18
  • Did you check if TCP/IP is enabled and port 1433 is open in firewall ? `C:\Windows\SysWOW64\SQLServerManager12.msc` – Searching Nov 18 '16 at 00:02
  • @SushiHangover I have enabling the audit logs for any attempt to log in and can see there are no logs made when I attempt to establish a connection – Jono_2007 Nov 18 '16 at 21:12
  • @Searching I have setup a custom port for the SQL Server however I have turned the entire firewall off to test whether it was a firewall problem and this had no effect on connecting – Jono_2007 Nov 18 '16 at 21:13
  • @Dai I can confirm that using Free TDS and the TSQL command that I can connect to the database – Jono_2007 Nov 18 '16 at 21:27

1 Answers1

0

I decided to spin up another Linux instance (Debian this time) to see if it could possibly be an environment issue. I installed the latest mono, etc. Running the same application actually gave me more information then running on the Ubuntu instance:

Server does not exist or connection refused. ---> System.Net.Sockets.SocketException: Could not resolve host '<Host>\<Instance Name>'

Previously I did not get the extra SocketException stating that it could not resolve the host. I don't know why I didn't get this information on the Ubuntu instance.

This led me to remove the Instance Name off of the connection string. As soon as this was done, the application started working as expected.

Jono_2007
  • 1,016
  • 3
  • 12
  • 23
  • When you removed the Instance Name, did you retain the rest of the connection string "as-is"? Does the updated version work in both Ubuntu and Linux? – oarevalo Oct 19 '17 at 22:09
  • From what I recall (testing my memory) I left it as is aside from removing the instance name. This was in a Ubuntu instance 16.04 at the time, I can't speak for how it would be in any other distro. Sorry can't be much more use – Jono_2007 Oct 19 '17 at 22:21
  • thanks. I have the same issue, but in my case removing the instance name didn't help. It just changed the error message to `"Mono.Data.Tds.Protocol.TdsInternalException: Server closed the connection....` – oarevalo Oct 21 '17 at 00:05