Issue connecting to MS SQL Server running on non default port 1433
See original GitHub issue@mahesji commented on Fri Feb 09 2018
Issue Title
Issue connecting to MS SQL Server running on non default port 1433 from Linux environment
OS Version Linux 4.4.0-109-generic #132~14.04.1-Ubuntu SMP Tue Jan 9 21:46:42 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
dotnet core project settings
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<RuntimeFrameworkVersion>2.0.5</RuntimeFrameworkVersion>
</PropertyGroup>
<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.5" />
<PackageReference Include="System.Data.SqlClient" Version="4.4.2" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.2" />
</ItemGroup>
</Project>
General
Using System.Data.SqlClient to connect to Sql server database. Following the sample in this post https://blogs.msdn.microsoft.com/dotnet/2016/11/09/net-core-data-access/
It works fine if the sql server is listening on port 1433 but fails when connecting to sql servers listening on port 1434. Confirmed that there is no network / firewall issues that that is blocking the ports. Able to connect to the same sql server on port 1434 using java code. This connection string works > Server=myhostname,1433;Database=mydatabase;User Id=myuser;Password=mypassword; This connection string does not work in above linux environment. Works fine on windows Server=myhostname,1434;Database=mydatabase;User Id=myuser;Password=mypassword;
Both connect strings work fine in Windows environment.
Record Fetch Error: 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: 35 - An internal exception was caught)
@usergiga commented on Fri Feb 09 2018
If an instance of SQL Server is listening on any other port, than 1433. You have to specify a server-alias or change the standard port globally. You can have SQL Server listening on multiple ports.
@mahesji commented on Mon Feb 12 2018
@usergiga , Thank you for the reply. I have the alias created and that doesn’t seem to help. The connection works fine in Windows runtime. Have this issue only in the Linux (Ubuntu) runtime.
Issue Analytics
- State:
- Created 6 years ago
- Comments:18 (3 by maintainers)
Thanks @cheenamalhotra,
Looks like latest nuget package works fine. Now we have some issues under load tests. Seems like linux libs are handling connections less efficiently than windows.
We get tcp connection establishment timeouts after a certain load has been achieved.
The effect does not end with sql … same issues starts with any other outbound network communications like rabbit mq and basic http requests…
Still investigating root cause.
@mahesji have you confirmed that the TCP connectivity from Linux to the port is working fine? Also have you tried specifying the IP address of the server instead of the host name in the connection string. To find out if the TCP port on the Windows server can be connected to, from linux or not, use
nc -vz hostname port
(assuming you have netcat installed on the linux host)