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

时间:2017-02-16 19:08:07

标签: msbuild azure-devops localdb azure-pipelines sql-server-2014-localdb

我正在使用localdb进行一些Entity Framework存储库集成单元测试。 我已经实现了标准的构建配置,在读取初始问题之后我应该初始化并启动SQL Local DB。 为此,我添加了以下内容来测试项目后期构建:

"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 已初始化OK,但 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

非常感谢任何帮助。

0 个答案:

没有答案