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.