localdb RESTORE SQL 適用於我的 Win 10 機器,但不適用於我的 Azure 管道代理

localdb RESTORE SQL 適用於我的 Win 10 機器,但不適用於我的 Azure 管道代理

我有一個 Azure 管道拒絕執行我的整合測試(嗯,在執行測試之前,它必須從 .bak 檔案建立必要的資料庫 - 這就是失敗的部分)

此 SQL 作為我的 MSTest 例程的一部分被呼叫ClassInitialize

IF DB_ID('saleslogix_full') IS NOT NULL
    BEGIN

      ALTER DATABASE [saleslogix_full] SET SINGLE_USER WITH
      ROLLBACK IMMEDIATE;

      DROP DATABASE [saleslogix_full];

    END

restore database saleslogix_full
from disk = 'C:\x\y\z\data-snapshots\saleslogix_full.bak' with Recovery,
move 'saleslogix_full' to 'C:\x\y\z\saleslogix_full.mdf',
move 'saleslogix_full_log' to 'C:\x\y\z\saleslogix_full_log.ldf'

以上是透過連接到(localdb)\MSSQLLocal伺服器的「主」資料庫來呼叫的。同樣,「在我的機器上執行」執行 Visual Studio 2019 windows-2019vs2017-win2016


其他詳細資訊 - Azure 代理程式日誌片段

A total of 6 test files matched the specified pattern.
  X SeededSuccessfully_SalesforceIntegration
  Error Message:
   Class Initialization method MyCorp.Data.ReplicationWorker.Tests.Test1.ClassInit threw exception. System.Data.SqlClient.SqlException: System.Data.SqlClient.SqlException: Cannot create more than one clustered index on table 'dbo.sysschemaarticles'. Drop the existing clustered index 'PK_dbo.sysschemaarticles' before creating another.
Database 'saleslogix_full' was restored, however an error was encountered while replication was being restored/removed. The database has been left offline. See the topic MSSQL_ENG003165 in SQL Server Books Online.
RESTORE DATABASE is terminating abnormally.
Processed 1120 pages for database 'saleslogix_full', file 'saleslogix_full' on file 1.
Processed 2 pages for database 'saleslogix_full', file 'saleslogix_full_log' on file 1..

現在,埋藏在上述日誌訊息中的寶石是: Cannot create more than one clustered index on table 'dbo.sysschemaarticles'. Drop the existing clustered index 'PK_dbo.sysschemaarticles' before creating another

在我深入研究如何做到這一點之前,任何人都可以為我指出一個方向為什麼這適用於我的 Windows 10 機器,但不適用於我的 Azure 管道代理?我最初的直覺是說這是「localdb」SQL 版本的差異

答案1

我最後放置了try{...}catch{..}負責轟炸 SQL 語句的 .NET 程式碼。

捕獲特定於System.Data.SqlClient.SqlException錯誤

在 catch 中,我執行以下 SQL:

"ALTER DATABASE saleslogix_full SET ONLINE"

我所有的整合測試似乎都通過了資料庫

相關內容