I am trying to connect to an SQL Server database that is currently hosted on my local machine. I am using the following code to connect:
public class DBConnect {
Your problem might get solved by simply TURNING OFF the WINDOWS FIREWALL. Firewall will prevent your real device from establishing connection with your local MS SQL server. By doing so it worked fine for me.
BUT since turning off firewall is not a good idea, configure the Windows Firewall for Database engine access, click this link and follow the steps.
https://docs.microsoft.com/en-us/sql/database-engine/configure-windows/configure-a-windows-firewall-for-database-engine-access?view=sql-server-ver15