Cannot connect to AWS RDS SQL Server Database from Azure WebJob - azure

I am trying to connect to an SQL Server 2012 database in AWS RDS. Code works in Debug which tends to prove that the connection string, the AWS configuratio... are all good. I checked the connection string deployed in Azure with FTP, it is all well and good but when I call Connection.Open(), I get the following error (relevant part of the stacktrace) :
[01/26/2016 12:45:00 > 8c2620: INFO] 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
[01/26/2016 12:45:00 > 8c2620: INFO] at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
I tried to set up a network security group in Azure (allowing all ports/all IPs/TCP/UDP In/Out). It did not help but I was not completely able to understand if the WebJob is impacted by this security group (I am new to Azure and find the interface a bit confusing). Is there a way to link the policy to the job or is the policy applied server wide ?
I should mention that I am using free accounts for both AWS and Azure (which might limit my options ?)
Did anyone get that problem ? Does anyone have any hint ?
Thanks in advance

Adding this as an answer so that other folks might also benefit
First check to see if you have the default DB security groups that are created when you host an RDS instance.
If so, As per this AWS link, they request you to actually delete the DB security group.
You should try and remove these and then check connectivity again.
Hope this helps.

Ok Folks, Try this I am pretty sure it will work
it worked for me
1. Go to security group.
2. Choose the default group.
3. Go to the Inbound group.
4. Click Edit then change the source option from Custom to Anywhere.
5. Save.
That's it
Please reply if it worked.
MohaBassam

Related

Azure Function VNet integration breaks randomly

I'm using Azure Functions with .NET 6 on an S1-tier App Service Plan with regional VNET integration. In our scenario, we execute some SQL queries accessing an On-Prem database which works pretty fine at the first glance. Unfortunately, sometimes the virtual network connection seems to break and our queries run into 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: TCP Provider, error: 0 - An attempt was made to access a socket in a way forbidden by its access permissions.) An attempt was made to access a socket in a way forbidden by its access permissions.
After disconnecting and reconnecting the function from VNET, it starts working again as expected (I found this approach here)
But it seems like this is just a really poor workaround. Does anybody know how to fix this indefinitely? I've already tried creating a new function app but that didn't change anything.
• According to the error that you are encountering, there might be some issues with the Firewall in the on-premises environment or the TCP/IP connection being established. Thus, I would suggest you to please check all the issues mentioned in the documentation link below and verify whether all the instances of practices mentioned in it are followed correctly: -
https://learn.microsoft.com/en-us/troubleshoot/sql/connect/network-related-or-instance-specific-error-occurred-while-establishing-connection
• Secondly, I would suggest you to please check the SQL Browser Service in the on-premises SQL Database server and check whether ‘UDP port 1434’ is whitelisted for communication between the two environments or not along with TCP 1434. Also, when executing SQL queries to access the on-premises SQL DB, ensure that the instance name is input correctly along with the port number. Also, when mentioning the port number, ensure that it is preceded by ‘,’ and not ‘:’.
• Finally, I would suggest you enable diagnostic logging for an app service plan by referring to the below documentation link that will help you figure out the reason for your connection error to the SQL DB. Also, you can browse through the Kudu console by accessing the url:- https://****.scm.azurewebsites.net/ (enter your website name instead of ****). You should be able to find the log files under the debug console. Please check if there are any failure logs: -
https://learn.microsoft.com/en-us/azure/app-service/troubleshoot-diagnostic-logs#:~:text=To%20enable%20application%20logging%20for,itself%20off%20in%2012%20hours.
https://github.com/projectkudu/kudu/wiki/Investigating-issues
Note: - Please check whether your API URL connection string used in the function app is being replaced correctly and troubleshoot your connection variables thoroughly.

Can't connect to new Azure SQL Server instance

I've just spun up an instance Azure SQL server. I can connect to it from the Azure Portal, but I get a timeout error when trying to connect with SQL Management Studio (and other methods):
Cannot connect to *server*,*port*.
Additional information:
A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: TCP Provider, error: 0 - The semaphore timeout period has expired.)
(Microsoft SQL Server, Error: 121)
The semaphore timeout period has expired
I've been searching for a solution but the only thing I find about the error message is that the database is under heavy load, which seems unlikely concidering it was just created!
Anybody know what can cause this problem?
Thanks!
Error 121 has always been considered a network related error as you can read in this Microsoft Support article. The Internet service you receive, network adapters are things you should consider examine.
Please consider to click the "Options" button of SQL Server Management Studio, on the "Connection Properties" tab, try setting a greater value for the "Connection time-out" setting.
If you need to use a Corporate VPN to connect to Azure SQL Database, make sure you are connected to the VPN.
Problem is related to a Firewall in the middle doing SSL inspection.
I Suggest to try requesting your firewall admin to add an exemption on the SSL Inspection engine , or try using another connection not doing SSL inspection.
So it seems it was the company firewall that was blocking the traffic. I tried from another network entirely and then I could access the server.
I guess my two alternatives now are either to unblock 1433 in the company firewall, or to open another port in Azure SQL Server, which doesn't seem possible at the moment.

Getting an intermittent error while connecting to on-premise sql database from Azure service

Created an azure MVC website, from service (controller) code we are connecting to an on-premise sql server using Azure Hybrid Connection. Intermittently we are facing below issue.
"A transport-level error has occurred when receiving results from the
server. (provider: TCP Provider, error: 0 - The specified network name
is no longer available.)"
Please provide suggestions to resolve this issue.
You can try following solutions :
Try increasing connection time-out.
check if remote connection is enabled.
Try adding firewall exception.
First of all the error means either the networks has some extra latency, the database is down or you may have too many concurrent connections open the database.
(Make sure you are closing all open datareaders.)
also it may be due to this
These are transient faults and are to be expected in the cloud. Implementing defensive programming is usually a must in the cloud. Try using some retry logic. Microsoft's transient fault exception library is an excellent start. Though meant primarily for SQL Azure and Azure Service bus, you can use the library for SQL IaaS.
In my opinion, 98% sure, because I recently had the same experience, it is a network issue from the server provider.
For instance: if you are rent the server from Ionos, by default all remote connections are blocked, even though you disable the firewall in the server. You still won't be able to connect remotely. You can, however, do your work on the server without any problem.
To connect remotely, you have to contact the server provider. They will explain how to enable firewall ports from your control panel.
I contacted my server provider as I almost get frustrated. Here was their response.
enter image description here
After this, every permitted client can connect remotely to the server.
I wish you success.

Connecting Apps with Windows Azure Connect - Problem connecting

I'm following the Connecting Apps with Windows Azure Connect lab in the Azure Training Kit.
I've followed the instructions to set up the Groups and Roles, and the Activated EndPoints.
I've updated the SQL Express settings and restarted the service
I've installed the local endpoint, which gives the following text.
I've added a new Windows Firewall rule
This endpoint is configured to
connect, and can connect to other
resources in Windows Azure Connect.
I still get this error displayed in the browser.
Sorry, an error occurred while
processing your request.
Message: The underlying provider
failed on Open. Inner 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: TCP Provider,
error: 0 - No such host is known.)
Any ideas on why this might be or suggestions on finding out where it is failing?
Thanks.
Update
I found this link "Windows Azure Connect and Symantec Endpoint Protection" describing a similar problem; as the title suggests Symantec EndPoint Protection could be the problem.
Although in this case, removing Symantec did not fix the problem
Update 2
some messages from Event Viewer - this set is repeated every 2 mins, they dont appear connected to a web page request.
at 9:29:40 [Information]
The user SYSTEM has successfully
established a link to the Remote
Access Server using the following
device: Server address/Phone Number =
sydrelay4.windows.azure-test.net
also at 9:29:40 [Information]
The link to the Remote Access Server
has been established by user SYSTEM.
at 9:29:41 [Error]
The user SYSTEM dialed a connection
named Windows Azure Connect Relay2 1
which has failed. The error code
returned on failure is 798.
at 9:29:45 [Information]
The user SYSTEM dialed a connection
named Windows Azure Connect Relay2 1
which has terminated. The reason code
returned on termination is 631
I had the exact same issue, Symantec et al. I was able to resolve it by adding the .cer certs I used in the Azure portal for the Hosted Services -> Management Certificates to my personal certificates collection via MMC and then rebooting my computer.
Hope that helps.
If you’re receiving a message like that, it’s possible that your current location has an outgoing port blocked.
Check this thread:
SQL Azure : Connection to SQL Azure throws exception
Is your machine behind a proxy? If so try to run the following commands to set proxy for the local system account:
bitsadmin /UTIL /SETIEPROXY LOCALSYSTEM NO_PROXY
bitsadmin /UTIL /SETIEPROXY LOCALSYSTEM MANUAL_PROXY a.b.c.d:80 NULL

SqlException & Timer Job

I found the below ULS Log entries, Timer job (OWSTimer.EXE) is causing this however would like to know the name of the Timer-job, how can i achieve this? (without enabling verbose logging)
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.
SqlError: '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.)' Source: '.Net SqlClient Data
Provider' Number: 258 State: 0 Class:
20 Procedure: '' LineNumber: 0 Server:
''
You could try using a tool like wireshark to see what kind of network traffic is being generated and under which account a request and to which SQL box is being made. I suspect this error is triggered one of the following ways (first 2 unlikely ones, then the likely problem):
Not likely: a security issue, sql is inaccessible to the account the call is made under, maybe originating from a timerjob that uses a (non sharepoint) database of it's own.
Not likely: a (non sharepoint) database used by a timerjob doesn't exist anymore, or the sql box it was running on is unreachable.
Very likely, a webapp is running using either the local service or the network service account (or any other local user). Code in timerjobs etc. bound to that webapp might use that account. If it is a local account, it won't have access to a database on another machine if you haven't granted access to that account on the sql machine. And granting a local account from machine A access to machine is not something you would normally do (I hope).

Resources