Azure Web Job SQL Connection String Server not found (On Prem SQL)? - sql-server

I have a web app service in Azure with web job attached. The web App is connected to my company network via VNET in Azure but the webjob wont connect to the on premise sql instance.
here is the format of connection string I am using: which works locally through visual studio.
<add name="conn" connectionString="Server=192.0.0.0\SqlInstance;Initial Catalog=Database ;user id=xxx; password=xxx" providerName="System.Data.SqlClient" />
I am only trying to select some data at the moment to prove the concept but cant get it working.
I am getting 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)
I have check the sql instance and Allow Remote connections is enabled and firewall on the server is also disabled.
is my connection string wrong?
Thanks

I have found the problem - turns out our SQL instances are not using the standard ports. once I found out the correct port using SQL Config manager and applied it to the connection string it started working.
connectionString="Server=192.0.0.0\SqlInstance,5000;
Thanks to #Jason Haley for pointing me towards Kudu which helped me find the issue.

Related

Accessing SQL Server from Azure DevOps Pipeline

Problem
I have setup an Azure Pipeline, and the problem I have is that during the Test Assemblies part of the Pipeline it is failing as it can't resolve the connection string/find my SQL Server.
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) ---> System.ComponentModel.Win32Exception: The network path was not found
In this scenario, I want to avoid creating a mock and ideally have the code directly communicate with SQL Server.
The SQL Server is sat on an Azure VM, so it's not a 'Azure SQL Database' service.
What I've Tried
I have opened the ports on the Azure VM to allow traffic from all regions/IP ranges used by Azure DevOps (I have found online that this is required). I have also tried pointing the connection string inside the Pipeline 'Test Assemblies' to a different (on-premise) windows server which holds an instance of SQL Server, but it is still not able to find/connect to SQL.
When connecting to SQL from my local (both the Azure VM and on-premise server) I can connect. We also have a few other services using the SQL Server sat on the Azure VM, so I am confident that the connectivity issue is with connecting from an Azure Pipeline.
Has anyone had this issue before?
Update
I have updated the connection string to directly refer to the port i.e.
**.***.**.***,1433
And the error message has now changed to:
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: 0 - The wait operation timed out.) ---> System.ComponentModel.Win32Exception: The wait operation timed out
I now have it working.
After having the Azure DevOps region changed from West Europe to UK South, my DevOps can now communicate with SQL Server on my VM (with the required IP addresses white listed as per Leo Liu-MSFT's comment).

Dotnet core application cannot connect to SQL server using IIS, only when using IIS Express or Kestrel

I have a .NET Core web application that fetches some data from a SQL Server. I connect to the SQL Server over the internet.
When I run the application with IIS Express or Kestrel, I can connect to the database server and retrieve data. I can also successfully connect to the database server using SQL Server Management Studio.
Here is the connection string I'm using:
"ConnectionStrings": {
"DefaultConnection": "Server=my-sql-server.someurl.com; Initial Catalog=my-sql-database; User ID=my-user-id; Password=my-password;"
}
But when I try to run the same website, on the same machine, in IIS, I get the following error message:
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: 0 - No such host is known.)
I'm suspecting this has something to do with the dotnet core/IIS combination, and not a firewall/network/authentication issue, but I might be wrong.
The issue was simply that I was looking at the wrong connection string.
I have appsettings.json containing one connection string and appsettings.Production.json containing another.
When running the application with IIS Express or Kestrel, the first one is used, but when I publish the app and then run it under IIS, the environment is set to Production, and the production settings are used instead.
The problem was that the production connection string pointed to a database server that didn't exist anymore.
I solved this issue by adding LocalSystem to Identity in Web site Application pool.
Steps:
Select website application Pool
Right click and click Advanced Setting
Click on Identity, and change it to LocalSystem
You need to enable TCP/IP protocol on sql server. Please use following link:
Why am I getting "Cannot Connect to Server - A network-related or instance-specific error"?

SQL Server Express connection string error

Trying to figure out the correct connection string for a SQL Server Express database. Trying to publish my app to IIS and test before publishing to my hosting site.
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)
I started here and also used connectionstrings.com. I also started reading the deploy asp.net app using SQL Server Compact article here
Using this connection string
Data Source=.\\SQLExpress;AttachDbFilename=H:\DB\Guestbook.sdf;Integrated Security=True
I get the above error
This connection string
<add name="DefaultConnection"
connectionString="Data Source=.\SQLEXPRESS;Integrated Security=SSPI; database=Guestbook; AttachDBFilename=|DataDirectory|Guestbook.sdf"
providerName="System.Data.SqlClient" />`
throws a trust level error. I've changed to medium and full and still get one of the two errors.
I've tried a variation of a few different strings with no luck.
Thanks
Please verify that SQL Service is started in services.msc and use the complete instance with the hostname ej: HOSTNAME\SQLEXPRESS
The file extension indicates that this is not a SQL Server Express database, so you must use:
Data Source=<Full path to file>
or
Data Source=|DataDirectory|Guestbook.sdf

provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified No fix?

I recently added a second site to my server. That site gives me the dreaded:
System.Data.SqlClient.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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
I have no idea why I am getting this. I've gone through this and this to no avail. This is a new MVC4 application I have at beta.vinformative.com in IIS 7. The other site is a MVC3 site at vinformative.com. It is running fine. Both of their databases have the exact same connection string and they are both on the same SQL server. I've given the same user mapping and role membership for NT Authority\Network Service to both databases.
Here is what I've tried so far:
MSSQLSERVER SQL Server service is running along with SQL Server Browser, and SQL Server Agent
I've added a firewall inbound rule for SQL Server browser
Made sure TCP/IP is enabled in sql server configuration
Added port 1433 TCP to the firewall
Enabled remote connection to db server
Successfully pinged the machine
Used portqry to see the db server on UDP 1434
I can connect to the site locally when I am remotely logged into my server. Furthermore, I have an ELMAH instance in the application for error logging and that is updating the database correctly. I feel like I am taking crazy pills because this should be working and I can't find an outright error. Please help!
Here is my connection string
<add name="vfContext" connectionString="Data Source=vinformative;Initial Catalog=vf3;Integrated Security=True" providerName="System.Data.SqlClient" />
Could be EF - see here.
Also, remote access cannot work with "Integrated Security=True" as far as I know, should use "User ID=******;Password=****;Integrated Security=False".

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