Connecting to Azure database when running web application locally - c#

I have been developing a basic Azure based web application and have run into a problem. The application queries a database that is hosted on Azure and returns the values to the user. When I run the application locally on my private wifi network and when I deploy the application to Azure, it runs fine and the queries are returned correctly. However, when I run the application locally on my companys wifi, I get the following error:
An exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll but was not handled in user code
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: TCP Provider, error: 0 - No connection could be made because the target machine actively refused it.)
Can anyone tell me if there is any additional code I need to add or what exception I need to ask to be put in the company's firewall in order to allow me to run and test the application locally?

Related

Entity Framework cannot connect to Database via Azure Hybrid connection

I'm currently working on an API, to access data from a SQL Server that is hosted locally. My app is being hosted through an Azure web app. I'm also using Entity Framework 6 in my application to access data. Since my data can't be in the cloud, I created an Azure Hybrid connection to create a relay to my SQL Server.
However, I keep running into this error (see below). I don't understand why this happens. I have checked my firewall rules to make sure that connections from Azure are being permitted. I have also verified that my connection string is correct and that I'm using the right port number. I also verified that remote connections are allowed on the SQL Server.
In case anybody is wondering I'm running SQL Server 2012. Does anyone have a fix for this issue? I would really appreciate it.
Thanks in advance.
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.

SqlDependency/Query notification - SQL Server reboot

I have an application running on a server which has a SqlDependency / query notification - monitoring changes on a table on a different server.
It works fine until we reboot/restart SQL Server. When SQL Server is rebooted due to some maintenance and patches, the other application throws the following errors and stops. I can definitely say it stops because it does not monitor changes once the SQL Server is up and running.
I have to restart the application to resubscribe to the query notification. I am not throwing any exception inside the code that would stop the application. I am catching the exception and sending an email.
System.Data.SqlClient.SqlException (0x80131904): A transport-level error has occurred when sending the request to the server. (provider: TCP Provider, error: 0 - An existing connection was forcibly closed by the remote host.) --->
System.Data.SqlClient.SqlException (0x80131904): 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.
I am new to SqlDependency / query notifications so I am not sure whether this is an expected behaviour or something I am doing wrong. It's my understanding(from other posts (SqlDependency Reliablity?) that I don't have to restart the job to resubscribe.
Appreciate your time and answers
This is normal because when you restart the sql server, the service was stopped and any application that is connected to sql server will be thrown this error:
A network-related or instance-specific error occurred while establishing a connection to SQL Server.
To avoid this problem, you can use a different instance for every application. You can install new server instances with different names to avoid this issue. Which when you restart a single sql server instance, the other sql server instance will still remain online.
You can follow these steps to install or create a new sql server instance:
https://4sysops.com/archives/how-to-create-a-new-sql-server-2012-instance/

WCF database connection working but fails when accessing database from WPF

I have a weird error occurring i've hit a brick wall with. I have my WCF service hosted on my web host, I can access this fine. I have a database set up on my web host and I have created the connection string to the database within my WCF web.config.
When I test the database connection to the database on the live server from my local WCF project the connection works fine. When I run my WPF application, it creates a contract with my WCF service (WPF app is local and WCF is live) I get the
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 really don't understand how I can connect to the database from my local WCF project but not from my live one? Anyone got any tips on how to either resolve this or even how to identify where the issue is occurring?
RESOLVED: Apologies for wasting your time but I had the database connection string hardcoded in a configuration file as well as in the web.config which is what was causing the problem. I meant to fix this before and forgot all about it.

Windows service network error

I have made a windows service and through that service I am doing operations on the database. The machine that I have installed the service is in India and the server is in Singapore. When this service runs I get an error such as
" 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 connection could be made because the target
machine actively refused it.) "
I have a connection string such as
return "server=122.0.122.222,5222;database=ABCD;user id=abc101;password=xyz";
this is in a function that is returning a string. I am catching this string in another string and passing it to the connection object.M I doing anything wrong here.?
But I have tested this service at my house. It works just fine. But when deployed at clients end I get the above error. Any idea why this mite be happening.? Is it related to internet connection but the internet connection is fine. DO I have to give some permissions from my service to make a connection or the IT team of the client should have to give some permissions at their end.?
Please help.
Thanks In advance

Desktop application cannot connect to database but web application can

I have written a C# desktop (winforms) application which is essentially a clone of a web application I wrote. The web application is able to talk back and forth with the database just fine. However, when I install the desktop application, I get the following error:
A network-related or instance-specific error occurred while establishing a connection to SQL Server
I am using the exact same connection string in the desktop application as I am using in the web app which looks like this:
"Data Source=tcp:s08.winhost.com;Initial Catalog=THEDATABASE;
User ID=USERNAME;Password=******;Integrated Security=False;"
I am unable to use SQL Server Configuration Manager as my databases are hosted on Winhost.com. However they have made it clear to me that the proper ports are open, named pipes are on and SQL Browser is configured correctly. If anyone has had a similar problem, please let me know what you did to resolve this issue. I have also included the entire error below.
Thanks
************** Exception Text **************
System.Data.SqlClient.SqlException (0x80131904): 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 - A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.) ---> System.ComponentModel.Win32Exception (0x80004005): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
Remove TCP protocol name and port number and try with full hosting website address..something like this
Data Source=www.winhost.com;Initial Catalog=THEDATABASE;
User ID=USERNAME;Password=**;Integrated Security=False;
Eventually I found that the problem was a proxy server. The application is being used by corporations who have proxy servers setup and due to this port 1433 was blocked. I ended up resolving the issue by creating a webservice.

Categories

Resources