首页 > 解决方案 > 在管道构建期间获取 sql server (express) azure devops

问题描述

我正在为 asp.net 应用程序设置管道。在集成测试任务期间,我需要连接到 SQL 服务器。我如何对管道说我需要 sql 服务?

我尝试了多个 microsoft 托管代理池(Windows Server 1803、Hosted 2017 和 2019)我使用 Windows Server 1803,问题是:

The operating system of the container does not match the operating system of the host.

我想正确设置一个临时 sql 服务器来运行测试。

我改用了localdb。

我在我的集​​成测试任务之前运行这个脚本

SqlLocalDB.exe create "DeptLocalDB"  
SqlLocalDB.exe share "DeptLocalDB" "DeptSharedLocalDB"  
SqlLocalDB.exe start "DeptLocalDB"  
SqlLocalDB.exe info "DeptLocalDB"

要与 powershell 连接:Invoke-Sqlcmd -Query "SELECT GETDATE() AS TimeOfQuery;" -ServerInstance "(localdb)\.\DeptSharedLocalDB"

要连接 sqlcmd:sqlcmd -S (localdb)\.\DeptSharedLocalDB

要连接 ac# 应用程序(connectionString):"Data Source=(localdb)\.\DeptS haredLocalDB;Initial Catalog=DeptLocalDB;Integrated Security=True;"

如果有人知道如何在 azure 管道上的容器中安装 sql 服务器,将不胜感激。感谢阅读

标签: azure-devopsazure-pipelineshosted

解决方案


Chocolatey 安装在windows-latest.

因此,如果您在 YAML 文件中定义:

  pool:
    vmImage: windows-latest

然后,您可以使用 choco 安装 SQL Server Express:

 - script: choco install sql-server-express

推荐阅读