Accessing SQL Server from Azure DevOps Pipeline - sql-server

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).

Related

ADF Copy Actitity issue

I have an issue where I can preview data from a source, a SQL Server connected through a Self-Hosted IR, but I cannot copy the data to a sink (Azure SQL DB on an EP).
The user account at the SQL Server level has access to the relevant tables, as can be verified by the fact that I can preview data. The sink side dataset also works, as I can use with similar data sources to the source.
If I, for example, try to fetch two specific rows, I can see them in the preview, but it takes 5 minutes for ADF to give an error message which is wildly misleading:
ErrorCode=SqlFailedToConnect,'Type=Microsoft.DataTransfer.Common.Shared.HybridDeliveryException,Message=Cannot connect to SQL Database: 'ServerName.database.windows.net', Database: 'DatabaseName', User: 'AdminUserName'. Check the linked service configuration is correct, and make sure the SQL Database firewall allows the integration runtime to access.,Source=Microsoft.DataTransfer.ClientLibrary,''Type=System.Data.SqlClient.SqlException,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 - 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.),Source=.Net SqlClient Data Provider,SqlErrorNumber=10060,Class=20,ErrorCode=-2146232060,State=0,Errors=[{Class=20,Number=10060,State=0,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 - 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.),},],''Type=System.ComponentModel.Win32Exception,Message=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,Source=,'
What am I doing wrong? Is there some setting I am missing?
Please check whether the Azure SQL DB(sink) is accessible from the server on which you have installed the self hosted IR.
YOu would need to whitelist the IP of the Self IR server in Azure SQL DB firewall rules and make some port opening in the IR server for Auzre SQL DB to be accessible.
Basically in case if an IR is being used in a copy activity, both the source and sink must be accessible from the server on which IR is set up

Why do I get an error 22300 when adding a new linked service on Azure?

I am new to Azure. I am currently exploring Azure Synapse. I have a local SQL Server Express database on my laptop and I wanted to connect it as a data source on my Azure Synapse. I selected SQL Server:
Now when I tested the connection I get the following error:
The problem is I get a 22300 error:
Cannot connect to SQL Database: 'DESKTOP-xxxxxx\SQLEXPRESS', Database: 'David', User: 'Bidi'. Check the linked service configuration is correct, and make sure the SQL Database firewall allows the integration runtime to access.
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), SqlErrorNumber=-1,Class=20,State=0,
Activity ID: eafe37de-fabf-43d6-914f-25e8685bb149.
I even tried enabling the port in the SQL configuration manager:
And I made a firewall rule to allow the port:
Unfortunately I still can't get the linked service on Synapse to connect to it.
Any help would be greatly appreciated.
You will need to install the Self-hosted integration runtime in your on-premises network, for example on the machine running SQL server:
A self-hosted IR is capable of:
Running copy activity between a cloud data stores and a data store in private network.
See the docs on how to install and configure the runtime .

Unable to refresh Power BI from Azure Virtual Machine connected to an on-premises SQL

I posted this issue in the Power BI community and Azure community but no answer at all. I hope someone can give me some light. I apologize if it's not the right forum but I am really stuck and I do not know how to solve it...
I am developing a report for a customer in Power BI. The source is a on-premises SQL Database. The customer gave me credentials and open the SQL Database just for my Static IP. From my computer or any other physical computer through my VPN works fine.
The customer doesn't want to install a Gateway in the server or any other computer, so as alternative, I thought using a Azure Virtual Server that I can automatically start and stop once a day just for the update of the report.
This Azure VM is connected with a OpenVPN Client to my VPN. So it's the same static IP (I've tested it).
When I open the report in the VM and go to Power Query, all the queries against the SQL Database work fine but the ones that have some Merge step. It breaks when the merge is expanded:
*DataSource.Error: Microsoft SQL: 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)
Details:
DataSourceKind=SQL
DataSourcePath=app.sciomac.com;SciomacProd
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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
ErrorCode=-2146232060
Number=53
Class=20*
The source of the queries are:
*QUERY1
Source = Sql.Databases("app.sciomac.com"),
SciomacProd = Source{[Name="SciomacProd"]}[Data],
dbo_Calls = SciomacProd{[Schema="dbo",Item="Calls"]}[Data]
QUERY2
Source = Sql.Databases("app.sciomac.com"),
SciomacProd = Source{[Name="SciomacProd"]}[Data],
dbo_Videos = SciomacProd{[Schema="dbo",Item="Videos"]}[Data]*
Individually both queries connect to the SQL Database without any problem, but when I make a merge step the query breaks when expanded.
I have the same issue if I tried to connect to a PostgreSQL db
Any idea how to solve it?
Thank you for your help.
Miguel

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

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.

how to connect SQL Azure using local ssms?

This may be a duplicate question, but i tried all way to connect the SQL Azure database from my local SSMS.
I have created Azure database in cloud and added my system IP in firewall configuration section, As I am on being corporate network and trying to connect azure database from my local ssms then i am getting below 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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) (Microsoft SQL Server, Error: 53)"
You need to add your IP in Azure as an allowed IP address.
Go to your database in the Azure portal, select configure -> Add to the allowed ip addresses.
Then connect to < Database name >.database.windows.net

Resources