Unable to access database on different subnet from IIS application - sql-server

I have a web server in a DMZ on a different VLAN and subnet than the trusted network. This web server must communicate with a database server on the trusted network, so the appropriate firewall rules have been applied. I am able to connect to the database from the web server using powershell and by using the ODBC Data Source Administrator snapin. However, running an IIS application throws the following 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) Inner Exception:
Source: .Net SqlClient Data Provider
I am using the same connection string in the web.config file of the IIS application as the one I use in powershell, which connects without any issue. Here is the connection string from the web.config:
"Data Source=192.168.1.xxx\SQLExpress;Database=mydb;uid=myuserid;password=mypassword;integrated security=false;"
The only difference in the powershell connection string is that I do not specify the provider. If I leave that out of the web.config there is no difference.
I have even disabled all firewalls on both servers for test purposes, but still get the same error.
As ping and tracert from the web server to the database server complete successfully and I am able to connect via powershell and ODBC Data Source Administrator, I have no idea why the IIS application cannot connect.

Is the TCP/IP Protocol enabled for the database instance?
On the machine with the Database instance installed, go to Start -> MS SQL Server 20XX -> Configuration Tools -> SQL Server Configuration Manager.
There go to 'SQL Server Network Configuration' -> 'Protocols for SQLExpress'. Check that TCP/IP is enabled (By default it is disabled).

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?

UWP cannot connect to local SQL Server

I'm creating a simple UWP application working together with my local DB server I set up with SQL Server Management Studio.
I can successfully set up a connection in the server explorer and run queries in the DB:
However when I run the application I get an error when the connection is being established:
System.Data.SqlClient.SqlException HResult=0x80131904 Message=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: 25 - Connection string is not valid) Source=Core .Net SqlClient Data Provider
I'm not sure if it's a problem with the connection string or what else it could be. I checked the firewall settings and everything seems to be fine. The SQL server settings also allow for remote connection.
Which SQL Server version is running?
Have you tried with the following connection string format?
Data Source=.\\MSSQLServer;Initial Catalog=PapaDario;Trusted_Connection=yes;
Before you connect to your database, some aspect of the SQL Server configuration needs to be changed. First, ensure that you've enabled TCP/IP for SQL Server. You can do that in the Computer Management console. Then make sure that your SQL Server Browser service is running.

Can't connect remotely to SQL Server 2014 on Windows Server 2012 R2

I am trying to install SQL Server 2014 on Windows Server 2012 R2. I can connect locally using windows authentication and sql server authentication, but when I try to connect remotely using hostname\instance, I get 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) (.Net SqlClient Data Provider)
In SQL Server Network Configuration I have shared memory and tcp/ip enabled and named pipes disabled.
http://snag.gy/GHY8X.jpg
Under TCP/IP Protocol, I have Enabled=Yes, Keep Alive=30000, and Listen All=Yes
http://snag.gy/kL5vK.jpg
Under IP Addresses, I have
http://snag.gy/lgoD6.jpg
The Windows Firewall is turned off (for now). The machines are not part of a domain just p2p workgroup.
The client machine is XP SP3 pro. I tried connecting using SMSS and odbc, but both failed.
Don't know if it is relevant, but I ran sp_readerrorlog on the server and I saw this in the logs
The SQL Server Network Interface library could not register the
Service Principal Name (SPN) [ MSSQLSvc/SERVER_2012:49184 ] for the
SQL Server service. Windows return code: 0xffffffff, state: 63.
Failure to register a SPN might cause integrated authentication to use
NTLM instead of Kerberos. This is an informational message. Further
action is only required if Kerberos authentication is required by
authentication policies and if the SPN has not been manually
registered.
Sql Browser is enabled and running.
Allow remote connections to this server is checked.
Turns out it was the firewall. I had only disabled the firewall for domain not for private network.

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.

Local IIS Web server cannot connect to SQL Server

When I use the local IIS Web server, my ASP.NET MVC application is unable to connect to SQL Server. The database is on another server. However, if I use the Visual Studio Development Server, it works just fine.
Anyone know what settings I'm missing? Should something change in my Web.config?
Yes, TCP/IP is enabled on SQL Server.
Here is the error I get -
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)
Here is my connection string -
connectionString="
SERVER=servername;
Initial Catalog=dbname;
User ID=userid;
Password=passwd"
providerName="System.Data.SqlClient"
I think you need to use IP address to connect remote database something like SERVER=59.230.212.12 in connection string. Try to connect database in management studio from where your IIS is installed . then use same setting in connection string .

Resources