0
votes

I'm having problems in connecting a .NET Core 1.1 application to a remote SQL Server, but only on my Mac because on Windows everything works well.

Said that it's not my application and I'm only trying to make it working, this is my connection string on appsettings.Development.json:

  "ConnectionStrings": {
    "MesDatabase": "Data Source=x.x.x.x\\BLABLA,49331; Initial Catalog=DBNAME; Uid=sa; Pwd=blablabla"
  }

This is the error I get opening the connection:

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: TCP Provider, error: 25 - Connection string is not valid)

I can't access the server, any idea? I'm almost sure that it's a stupid error on connection string but I cannot find it.

I also tried to create a .udl file on Windows, editing it with correct connection data and taking the resulting connection string opening it with notepad. Nothing, always "connection string is not valid" on Mac.

1
It makes no sense to specify both an instance name and a port number. Either specify the instance name, and then let the SQL Server Browser service resolve the port for you, or specify the port, but then leave out the instance name. Note: I have no idea if this is the cause of your error, just an observation that your current use of options isn't meaningful. - Jeroen Mostert
Thank you @JeroenMostert but in this case it's necessary, without it doesn't work on Windows too (Error Locating Server/Instance Specified). Maybe on that machine the service which resolves the port is not running. - Mauro Piccotti
Make sure port 49331 is not blocked by firewall or any other app on MAC - Pranav Singh
Are you saying connecting to tcp:x.x.x.x,49331 fails where tcp:x.x.x.x\BLABLA,49331 works? Because I'd find that very surprising. SQL Server Browser may not be running or not reachable, but in that case instance names aren't useful anyway. - Jeroen Mostert
Make an odbc connection to the server on the mac, you will likely face the same problems. If you don't, then you could target that odbc instead. Also, is that really the port number? It's in the 'high end random ports' range - Davesoft

1 Answers

0
votes

As Jeroen Monstert said:

It makes no sense to specify both an instance name and a port number. Either specify the instance name, and then let the SQL Server Browser service resolve the port for you, or specify the port, but then leave out the instance name.

My problem was due to the fact that in the connection string I had both the instance name and the port, in combination with a "probably bug" on .NET Core 1.1 because behaviour was different between Mac and Windows. In my case SQL Server Browser was down on the server so I needed to specify the port, and for this reason I had to remove the instance name from the connection string.