首页 > 解决方案 > AzureDevOps - Azure SQL Server 部署问题及解决方案

问题描述

部署 Azure SQL 服务器时遇到的众所周知的问题有哪些解决方案。

问题 1

##[error]System.Management.Automation.ParentContainsErrorRecordException: *** Deployment cannot continueAn error occurred during deployment plan generation.

问题 2

##[error]Publishing to database 'testdb' on server 'ajyatest.database.windows.net'. Initializing deployment (Start) Initializing deployment (Failed) *** Could not deploy package. Unable to connect to master or target server 'testdb'. You must have a user with the same password in master or target server 'testdb'.

问题 3

##[error]System.Management.Automation.RuntimeException: No resource found with serverName ajyatest1, serverType Microsoft.Sql/servers in subscription <SubscriptionId>. Specify the correct serverName/serverType and try again.

问题 4

Server name 'ajyatest1' is not in the right format. Use FQDN format like 'yyy.database.windows.net'

问题 5

##[error]System.Net.WebException: The remote server returned an error: (404) Not Found. 

问题 6

##[error]Start IP address of firewall rule cannot exceed End IP address.

问题 7

##[error]Invalid value provided for parameter: startIpAddress

问题 8

##[error] Named pipes provider, error: 40 – could not open a connect to SQL. 
Possible suggestions

问题 9

如何为 SQLPackage.exe 配置超时?

问题 10

托管代理是否支持使用 AAD 集成身份验证的 Azure SQL 数据库部署?

问题 11

Azure SQL 数据库部署 - 导入的 Invoke-Sqlcmd 不支持 connectionString

问题 12

SqlPackage.exe 参数/p:BackupDatabaseBeforeChanges=true在 Azure 上失败

问题 13

Azure SQL 发布 - SQL 脚本文件 - 无法将机密值作为变量传递

标签: sql-serverazureazure-devopsazure-sql-databaseazure-pipelines

解决方案


问题 1

##[error]System.Management.Automation.ParentContainsErrorRecordException: *** Deployment cannot continueAn error occurred during deployment plan generation.

原因

您尝试在其上部署 dacpac 的 SQL 服务器的目标平台与 dacpac 文件的目标平台不同。

可能的解决方案

  1. 将 dacpac 项目中的目标平台更改为与 SQL Server 的目标平台相同。 在此处输入图像描述

  2. 添加 /p:AllowIncompatiblePlatform=true 参数作为 WinRm SQL 服务器任务的附加参数。

问题 2

##[error]Publishing to database 'testdb' on server 'ajyatest.database.windows.net'. Initializing deployment (Start) Initializing deployment (Failed) *** Could not deploy package. Unable to connect to master or target server 'testdb'. You must have a user with the same password in master or target server 'testdb'.

原因

SQL 服务器的用户名或密码错误。

可能的解决方案

检查 SQL Server 的用户名和密码是否正确。[您可以使用 SSMS 验证用户名密码]

问题 3

##[error]System.Management.Automation.RuntimeException: No resource found with serverName ajyatest1, serverType Microsoft.Sql/servers in subscription <SubscriptionId>. Specify the correct serverName/serverType and try again.

原因

错误的 SQL 服务器名称是错误的。

可能的解决方案

检查 Azure 门户上是否存在同名的 SQL 服务器。

问题 4

Server name 'ajyatest1' is not in the right format. Use FQDN format like 'yyy.database.windows.net'

原因

未作为 FQDN 提供的 SQL 服务器作为输入。

可能的解决方案

正如错误中提到的那样,它以“yyy.database.windows.net”格式提供 SQL 服务器

问题 5

##[error]System.Net.WebException: The remote server returned an error: (404) Not Found. 

原因

检查端点 URL 以创建防火墙规则。验证端点的 URL 是否是最新的。

可能的解决方案

检查端点有什么问题。用户如何创建端点。

问题 6

##[error]Start IP address of firewall rule cannot exceed End IP address.

原因

End IP 小于 Start IP 用于创建防火墙规则。

可能的解决方案

起始 IP 地址应小于结束 IP 地址。

问题 7

##[error]Invalid value provided for parameter: startIpAddress

原因

IP 地址格式不正确。

可能的解决方案

起始 IP 地址应小于结束 IP 地址。

问题 8

##[error] Named pipes provider, error: 40 – could not open a connect to SQL. 
Possible suggestions

建议

对于 onPrem SQL 服务器 1. SQL 服务器名称应采用正确的格式 server\instance。2. 验证连接字符串。3. 检查是否在 SQL 实例上启用了命名管道 (NP)。4. 是否启用远程连接。

  For Azure SQL server 

1.它可能导致按应用程序节流。2. 尝试使用端口 1433 提供 Azure SQL 服务器名称。例如 servername.database.windows.net,1433;

问题 9

如何为 SQLPackage.exe 配置超时?

解决方案

/p:CommandTimeout=1200  /TargetTimeout: 1200 

问题 10

托管代理是否支持使用 AAD 集成身份验证的 Azure SQL 数据库部署?

解决方案

否,AAD 集成身份验证尝试使用运行代理的同一用户登录 SQL Server。由于托管代理用户出于安全原因将无权访问 SQL 服务器。因此它将失败。换言之,托管代理不支持 AAD 集成身份验证。以为您可以使用 Active Directory - 密码身份验证。

问题 11

Azure SQL 数据库部署 - 导入的 Invoke-Sqlcmd 不支持 connectionString

解决方案 导入的 Invoke-Sqlcmd 不支持 connectionString。安装 SQLServer PS 模块。

问题 12

SqlPackage.exe 参数/p:BackupDatabaseBeforeChanges=true在 Azure 上失败

解决方案

/p:BackupDatabaseBeforeChanges=trueoptions 适用于本地数据库。该选项不适用于 Azure,因为备份系统完全不同。

问题 13

Azure SQL 发布 - SQL 脚本文件 - 无法将机密值作为变量传递

解决方案

SQL 脚本文件支持秘密变量。确保您正在传递变量的参数,如下所示。

Invoke-Sqlcmd -ServerInstance "test.database.windows.net" -Database "Testdb" -Username "test"  -Password ******  -Inputfile "C:\test.sql" -variable "MYVAR1='$(variablevalue1)'", "MYVAR2='String2'" -ConnectionTimeout 120

调试工具和建议

SQLPackage.exe 参数的文档

SQL 包参数

为 SQLPackage.exe 配置诊断日志

/diagnostics:true

从任务中获取调试日志

system.debug使用值设置发布定义变量true

SqlCMD 参数

SqlCmd 参数

比较 SqlCmd 和 Invoke-SqlCmd 参数

SqlCmd 与 Invoke-SqlCmd 参数


推荐阅读