I get "error: 40 - Could not open a connection to SQL Server" when trying to create a new database on my azure sql server via the devops pipeline

Tim Jaszdziewski 21 Reputation points
2021-01-13T18:28:02.027+00:00

As stated in the title, I get the error: 40 when I run my devops pipeline that is supposed to create a new sql database on my azure sql server. The deploy part of my pipeline yaml file looks like this:

- stage: Deploy
  displayName: 'Deploy Web App'
  dependsOn: Build
  condition: succeeded()
  jobs:
  - deployment: DeploymentJob
    pool:
      vmImage: $(vmImageName)
    environment: $(environmentName)
    strategy:
      runOnce:
        deploy:
          steps:
          - task: AzureWebApp@1
            displayName: 'Deploy Azure Web App : webapp'
            inputs:
              azureSubscription: $(azureSubscription)
              appName: $(webAppName)
              package: $(Pipeline.Workspace)/drop/$(Build.BuildId).zip
          - task: SqlAzureDacpacDeployment@1
            inputs:
              azureSubscription: 'Azure-Abonnement 1 (xxxx)'
              AuthenticationType: 'server'
              ServerName: 'server.mysql.database.azure.com'
              DatabaseName: 'db'
              SqlUsername: 'user'
              SqlPassword: 'pw'
              deployType: 'SqlTask'
              SqlFile: '$(Pipeline.Workspace)/**/db.sql'
              IpDetectionMethod: 'AutoDetect'

I don't know if that is important but the content of my SQL file looks like this: "CREATE DATABASE IF NOT EXISTS db", "CREATE TABLE TBL()" and so on.
I already checked for errors in the credentials.
I allowed every Ip adress in the firewall configuration of my Azure SQL Server and also allowed full access of Azure services.
I know there are a lot of questions regarding this error but I'm really new to Azure and every solution I found so far didn't work for me.

Azure SQL Database
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
8,937 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.