Msbuild 使用localdb与Visual Studio联机错误进行集成测试-';包含数据库身份验证';必须设置为1

Msbuild 使用localdb与Visual Studio联机错误进行集成测试-';包含数据库身份验证';必须设置为1,msbuild,azure-devops,localdb,azure-pipelines,sql-server-2014-localdb,Msbuild,Azure Devops,Localdb,Azure Pipelines,Sql Server 2014 Localdb,我正在使用localdb进行一些实体框架存储库集成单元测试。 我已经实现了一个标准的构建配置,在出现初始问题后,我应该初始化并启动SQL本地数据库。 为此,我添加了以下内容来测试项目后期构建: "C:\Program Files\Microsoft SQL Server\120\Tools\Binn\SqlLocalDB.exe" create "V12.0" 12.0 -s 但我在本地和Visual Studio Online Build中遇到错误,如: The sp_configure v

我正在使用localdb进行一些实体框架存储库集成单元测试。 我已经实现了一个标准的构建配置,在出现初始问题后,我应该初始化并启动SQL本地数据库。 为此,我添加了以下内容来测试项目后期构建:

"C:\Program Files\Microsoft SQL Server\120\Tools\Binn\SqlLocalDB.exe" create "V12.0" 12.0 -s
但我在本地和Visual Studio Online Build中遇到错误,如:

The sp_configure value 'contained database authentication' 
must be set to 1 in order to create a contained database.  
You may need to use RECONFIGURE to set the value_in_use.
因此,经过一些研究之后,我添加了以下内容

sqlcmd -S "(localdb)\V12.0" -Q "EXEC sys.sp_configure N'contained database authentication', N'1';"
sqlcmd -S "(localdb)\V12.0" -Q "RECONFIGURE WITH OVERRIDE;"
这在本地修复了一些问题,但在VSO构建代理中,我仍然会遇到错误。似乎localdb初始化正常,但是SQLCMD可以找到刚刚创建的服务器实例。记录在下面

"C:\Program Files\Microsoft SQL Server\120\Tools\Binn\SqlLocalDB.exe" create "V12.0" 12.0 -s

sqlcmd -S "(localdb)\V12.0" -Q "EXEC sys.sp_configure N'contained database authentication', N'1';"

sqlcmd -S "(localdb)\V12.0" -Q "RECONFIGURE WITH OVERRIDE;"
LocalDB instance "V12.0" created with version 12.0.2000.8.

LocalDB instance "V12.0" started.

HResult 0xFFFFFFFF, Level 16, State 1
SQL Server Network Interfaces: Error Locating Server/Instance Specified [xFFFFFFFF]. 
Sqlcmd(0,0): Error : Microsoft SQL Server Native Client 10.0 : A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online..
Sqlcmd : error : Microsoft SQL Server Native Client 10.0 : A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online.. [D:\a\1\s\src\dotNET\hms.entappsettings.webapi\hms.entappsettings.repository.Tests\hms.entappsettings.repository.Tests.csproj]
Sqlcmd(0,0): Error : Microsoft SQL Server Native Client 10.0 : Login timeout expired.
Sqlcmd : error : Microsoft SQL Server Native Client 10.0 : Login timeout expired. [D:\a\1\s\src\dotNET\hms.entappsettings.webapi\hms.entappsettings.repository.Tests\hms.entappsettings.repository.Tests.csproj]
HResult 0xFFFFFFFF, Level 16, State 1
SQL Server Network Interfaces: Error Locating Server/Instance Specified [xFFFFFFFF]. 
Sqlcmd(0,0): Error : Microsoft SQL Server Native Client 10.0 : A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online..
Sqlcmd : error : Microsoft SQL Server Native Client 10.0 : A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online.. [D:\a\1\s\src\dotNET\hms.entappsettings.webapi\hms.entappsettings.repository.Tests\hms.entappsettings.repository.Tests.csproj]
Sqlcmd(0,0): Error : Microsoft SQL Server Native Client 10.0 : Login timeout expired.
Sqlcmd : error : Microsoft SQL Server Native Client 10.0 : Login timeout expired. [D:\a\1\s\src\dotNET\hms.entappsettings.webapi\hms.entappsettings.repository.Tests\hms.entappsettings.repository.Tests.csproj]
C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets(4714,5): Error MSB3073: The command ""C:\Program Files\Microsoft SQL Server\120\Tools\Binn\SqlLocalDB.exe" create "V12.0" 12.0 -s
C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets(4714,5): error MSB3073: The command ""C:\Program Files\Microsoft SQL Server\120\Tools\Binn\SqlLocalDB.exe" create "V12.0" 12.0 -s [D:\a\1\s\src\dotNET\hms.entappsettings.webapi\hms.entappsetting

非常感谢您的帮助。

您是否尝试过使用sqllocaldb.NET库,它是为这样的场景创建的?@ErikEJ否。你有我可以查看的链接吗?你能在你的生成代理中成功地手动运行
SqlLocalDB.exe
命令吗?@Patrick MSFT我不知道如何在Visual Studio Online生成代理中获得交互式控制台。创建实例的初始SqlLocalDB.exe命令运行正常,但sqlcmd.exe命令似乎无法使用“(localdb)\V12.0”连接定位服务器。是否尝试使用SqlLocalDB.NET库,它是为这样的场景创建的?@ErikEJ否。你有我可以查看的链接吗?你能在你的生成代理中成功地手动运行
SqlLocalDB.exe
命令吗?@Patrick MSFT我不知道如何在Visual Studio Online生成代理中获得交互式控制台。创建实例的初始SqlLocalDB.exe命令运行正常,但sqlcmd.exe命令似乎无法使用“(localdb)\V12.0”连接定位服务器。