Issue while connecting to SQL Db from linux VM through C# Application

Bartosz Gulla 0 Reputation points
2023-05-26T08:09:46.08+00:00

Hi
I encountered an issue while trying to connect to a Azur hosted MSSQL server instance from a Linux (Ubuntu 20.04) VM through C# application (.Net 6.0) using EF to connect to the DB
The error im getting:

 ---> System.Exception: Cannot connect to SQL Server Browser. Ensure SQL Server Browser has been started.
 ---> System.Net.Internals.SocketExceptionFactory+ExtendedSocketException (00000001, 11): Resource temporarily unavailable
   at System.Net.Dns.GetHostEntryOrAddressesCore(String hostName, Boolean justAddresses, AddressFamily addressFamily, ValueStopwatch stopwatch)
   at System.Net.Dns.GetHostAddresses(String hostNameOrAddress, AddressFamily family)
   at System.Net.Dns.GetHostAddresses(String hostNameOrAddress)
   at System.Net.Sockets.UdpClient.GetEndpoint(String hostname, Int32 port)
   at System.Net.Sockets.UdpClient.SendAsync(Byte[] datagram, Int32 bytes, String hostname, Int32 port)
   at System.Data.SqlClient.SNI.SSRP.SendUDPRequest(String browserHostname, Int32 port, Byte[] requestPacket)
   at System.Data.SqlClient.SNI.SSRP.GetPortByInstanceName(String browserHostName, String instanceName)

I have tried pinging the db adress and it was succesful
I did add ports 1433 and 1434 as allowed outbound connections on the vm as well as added the vm ip ass allowed inbound connection on the SQL server.
The same code running on my windows PC works without issues so im assuming its not an issue with the code.
What should i do to fix the problem?

Azure SQL Database
Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
7,551 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Bas Pruijn 951 Reputation points
    2023-05-26T10:04:14.9933333+00:00

    Is the Windows PC connecting to the same SQL Database?

    I can imagine there is some networking set-up involved. Your database might block public connections. You can check this by looking at the SQL Server, networking tab. Since you mention that you added the IP address of the VM to the firewall rules, I expect the network tab is showing 'selected networks' and under the firewall rules is shows the public IP of your VM.

    Some things that might go wrong here are:

    • SQL only accepting private connections (network tab showing 'disable' on public network access
    • you added the private IP address of the VM to the firewall rules of the SQL server
    • if your VM does not have a public IP, you should add a private endpoint and a private DNS zone to the VM's VNET.

    If the response helped, do "Accept Answer" and up-vote it