IIS can't connect to SQL Server using SQL Server authentication - sql-server

I have a very strange problem that I have tried to figure out for some time now but unsuccessfully. At work I am using a laptop for development. We have our application run locally on each developer's laptop, but we all use the same dev database. So when I take my work laptop home and connect it to our vpn, my laptop's IIS connects to SQL Server and everything works just fine.
The problem is when I try to use my personal desktop for work I connect it to the same vpn I connect my laptop to run the same code that is on the laptop with the same connection strings, but IIS can't connect to SQL Server and I get this 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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
On both computers I am able to connect to SQL Server using SSMS with no problem. On both computers I can run Integration Tests that hit the database just fine (integration tests use the exact same connection string that the application is using), but if I try to run the application it can't connect. I have tried changing all sorts of settings in IIS but to no avail.
Thanks for your help in advance.

Make sure SQL Server Service is running
If a named instance, make sure SQL Server browser service is running
Make sure SQL Server is configured to allow remote connections
Examine the SQL Server error log for messages confirming that SQL is listening on the expected network interfaces and ports
Test server connectivity with PING from the client machine
Test port connectivity using TELNET or PowerShell to the server and port (from step 4) from the client machine. For example
a. TELNET 1433
b. PowerShell: 1433 | % { echo ((new-object Net.Sockets.TcpClient).Connect("YourServerName",$)) "server listening on TCP port $" }
Check firewall settings if step 5 or 6 connectivity test fails

Related

Connect IIS in DMZ to SQL Server on intranet

I'm trying to connect IIS which is running on a server in the DMZ to a SQL Server instance on the company intranet. But, I'm getting the following error:
An unhandled exception occurred while processing the request.
Win32Exception: Access is denied.
Unknown location
SqlException: 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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
Do I need specific ports opened up on one of the servers? Or is there something else I need to do?
Considering your SQL server is running, start with the networking. On which port is your SQL instance listening (default 1433)?
If you don't know, open the SQL Server Configuration Manager (on the SQL Server). Navigate to the SQL Server Network Configuration > Protocols for %instancename% > TCP/IP > IP Addresses. Then, test if something is blocking this connection; on your IIS in PowerShell:
Test-NetConnection -ComputerName sqlservername -Port 1433
If this doesn't work, check the Inbound Rules for Windows Firewall on your SQL Server. Make sure you work on the right network profile and eventually speak to the one managing your network systems in your company.
Maybe your IIS can't resolve the SQL Servers hostname? Try using the IP and check your DNS configuration.
There might also be something off with your connection string. Mind posting it here?

SQL Connection from Azure Linux App Service web app

I have an asp net core web app and SQL Server database hosted in Plesk via a hosting company.
I have deployed a copy of the web app to an Azure Linux App Service. It uses the Plesk hosted SQL Server database. When i use the Azure App Service I get a connection error when accessing the Plesk hosted database.
SqlException: 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: 40 - Could not open a connection to SQL Server)
If I use the Plesk hosted web app it connects to sql server correctly as expected. If I then immediately use the Azure Linux web app it manages to get a SQL connection! In all cases the connection string is identical. Its like it needs waking up!
How can this be the case. I am at a loss as to why this is happens. Any ideas folks?
Properly, you need to add the outbound IP addresses in Azure App Service into the firewall of SQL Server which your SQL Server database existed.
edit
You could check the following aspects on your side refer to this.
Make sure SQL Server Service is running
If a named instance, make sure SQL Server browser service is running
Make sure SQL Server is configured to allow remote connections
Examine the SQL Server error log for messages confirming that SQL is listening on the expected network interfaces and ports
Test server connectivity with PING from the client machine
Test port connectivity using TELNET or PowerShell to the server and port (from step 4) from the client machine. For example a. TELNET
1433 b. PowerShell: 1433 | % { echo ((new-object
Net.Sockets.TcpClient).Connect("YourServerName",$)) "server listening
on TCP port $" }
Check firewall settings if step 5 or 6 connectivity test fails
For more information:
Troubleshoot connecting to the SQL Server Database Engine
Networking Related Commands for Azure App Services

Cannot connect to SQL Server From Clients in LAN

Yesterday I had no problems. Now when any client (even MSSMS from a client machine) tries to access sql server located on a server in the domain I get the following error: TITLE: Connect to Server
Cannot connect to SERVER\Instance
A network-related or instance-specific error occurred while establishing a connection to SQL Server. ...
SQL server is 2014 on a Windows 2012 R2 Server which also hosts the Active Directory.
I can connect using MSSMS from the server itself to the database. The log states that the service started and is listening on port 63782. I can also connect to sql server from the host machine using ip:port (192.168.0.2, 63782). But I cannot connect to it this way from the clients. (I made no changes to the firewall and the rule for lan-lan is allow all services and all connections).
Shared Memory, TCP/IP and Named Pipes are enabled on the sql server configuration Manager.
I can ping to the server from the clients and to the clients from the server.
The main difference between yesterday and today is that I had to reinstall the DNS on the server. The DNS appears to be working very well and I can't find any DNS errors on the server. I don't think its the firewall but I added two rules that allow UDP and TCP specifically within the local network (even though there is a policy which allows all traffic within the local network).
I am at a loss and would appreciate some assistance into solving the problem or even where to look.

Could not connect to SQL Server instance from one of the machines

I have two machines (a laptop and a desktop) connected to the same network throgh the same router and an SQL Server with 2 instances: ODD and EVEN, both instances have the same configuration (as far as I can see), including sa account settings.
From my desktop I can connect to both instances, but from laptop I can connect only to the EVEN instance, when I try to connect to ODD instance I get the following error:
Microsoft Visual Studio
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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
OK
I know that:
I have correct password, because I can connect to EVEN
I have correct firewall settings, because I can connect to EVEN and both instances use the same TCP/IP port 1433
I have properly configures server, because I can connect to the both instances from desktop.
How should I troubleshoot this issue? Is there any more detailed information about what went wrong? Why does Visual Studio uses named pipes and does not try TCP/IP for example?
Check Sql Server Configuration manager on your client and server to see if TCP/IP protocol is enable or not. you can even disable Named Pipes protocol there and see how it will effect on VS error message.
you can even check server setting by trying below command from command shell.
telnet server-ip 1433

SQL Server 2005 Remote Connection ( Over Internet )

I have installed SQL Server 2005 in mixed mode.
I am able to connect to Database "locally" i.e.
(Server-name/Instance or internal-ip/Instance) using both kinds of Authentication.
I have configured SQL Server for remote connection by following below steps
Steps:
Enable remote connections on the instance of SQL Server that you want to connect to from a remote computer.
Turn on the SQL Server Browser service.
Configure the firewall to allow network traffic that is related to SQL Server and to the SQL Server Browser service. Ref: http://support.microsoft.com/kb/914277#method3
In addition, I have turned off my firewall.
I am able to ping my computer through the External IP.
But when it comes to connecting to sql server, its giving the error.
"TITLE: Connect to Server
Cannot connect to <ip address>\SQLEXPRESS.
ADDITIONAL INFORMATION:
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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified) (Microsoft SQL Server, Error: -1)
For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&EvtSrc=MSSQLServer&EvtID=-1&LinkId=20476
Please help me,
I have referred many article and tested all possible solution, but nothing seems to be working for me.
It turned out to be an issue with Port Forwarding from my Modem/Router to respective Machine IP.
To resolve this issue, I just configured my Router so that it can accept the request on some specific port [External IP:port_number] and then map that request to my machine's [Internal IP:port_number] as multiple computers were connected to a single router.
Also, please make sure that Firewall on your server is configured correctly to accept the inbound network traffic on that specific port.

Resources