刪除資料層應用程式Delete a Data-tier Application

適用於: 是SQL Server 是Azure SQL Database 否Azure Synapse Analytics (SQL DW) 否平行處理資料倉儲 APPLIES TO: yesSQL Server yesAzure SQL Database noAzure Synapse Analytics (SQL DW) noParallel Data Warehouse

您可以使用 [刪除資料層應用程式精靈] 或 Windows PowerShell 指令碼來刪除資料層應用程式。You can delete a data-tier application by using either the Delete Data-tier Application wizard or a Windows PowerShell script. 您可以指定是否要保留、卸離或卸除相關聯的資料庫。You can specify whether the associated database is retained, detached, or dropped.

開始之前Before You Begin

當您刪除資料層應用程式 (DAC) 執行個體時,可以選擇三個選項中的一個,指定要使用與資料層應用程式相關聯之資料庫執行的動作。When you delete a data-tier application (DAC) instance, you choose one of three options specifying what is to be done with the database associated with the data-tier application. 所有的三個選項都會刪除 DAC 定義中繼資料。All three options delete the DAC definition metadata. 這些選項的差異在於它們使用與資料層應用程式相關聯之資料庫執行的動作。The options differ in what they do with the database associated with the data-tier application. 精靈不會刪除與 DAC 或資料庫相關聯的任何執行個體層級物件,例如登入。The wizard does not delete any of the instance-level objects associated with the DAC or database, such as logins.

選項Option 資料庫動作Database actions
刪除註冊Delete registration 相關聯的資料庫會保持不變。The associated database remains intact.
卸離資料庫Detach database 相關聯的資料庫會遭到卸離。The associated database is detached. Database Engine 執行個體無法參考資料庫,但是資料和記錄檔保持不變。The instance of the Database Engine cannot reference the database, but the data and log files are intact.
刪除資料庫Delete database 相關聯的資料庫會遭到卸除。The associated database is dropped. 資料和記錄檔會遭到刪除。The data and log files are deleted.

限制事項Limitations and Restrictions

在刪除 DAC 之後還原 DAC 定義中繼資料或資料庫沒有任何自動化的機制。There is no automatic mechanism to restore the DAC definition metadata or the database after you delete a DAC. 您手動重建 DAC 執行個體的方式取決於刪除選項。How you can manually rebuild the DAC instance depends on the delete option.

選項Option 如何重建 DAC 執行個體How to Rebuild the DAC Instance
刪除註冊Delete registration 從原狀的資料庫註冊 DAC。Register a DAC from the database left in place.
卸離資料庫Detach database 使用 sp_attachdbSQL Server Management StudioSQL Server Management Studio重新附加資料庫,然後從資料庫註冊新的 DAC 執行個體。Re-attach the database by using sp_attachdb or SQL Server Management StudioSQL Server Management Studio, and then register a new DAC instance from the database.
刪除資料庫Delete database 從刪除 DAC 之前所做的完整備份還原資料庫,然後從資料庫註冊新的 DAC 執行個體。Restore the database from a full backup made before the DAC was deleted, and then register a new DAC instance from the database.

警告

從已還原或重新附加的資料庫註冊 DAC 來重建 DAC 執行個體時,將無法重新建立原始 DAC 的某些部分,例如伺服器選取原則。Rebuilding a DAC instance by registering a DAC from a restored or re-attached database will not recreate some parts of the original DAC, such as the server selection policy.

權限Permissions

DAC 只能由系統管理員 ( sysadmin ) 或伺服器管理員 ( serveradmin ) 固定伺服器角色的成員或資料庫擁有者刪除。A DAC can only be deleted by members of the sysadmin or serveradmin fixed server roles, or by the database owner. 名為 SQL ServerSQL Server sa 的內建 系統管理員帳戶也可以啟動精靈。The built-in SQL ServerSQL Server system administrator account named sa can also launch the wizard.

使用刪除資料層應用程式精靈Using the Delete Data-tier Application Wizard

使用精靈刪除 DACTo Delete a DAC Using a Wizard

  1. [物件總管] 中,展開含有要刪除的 DAC 之執行個體的節點。In Object Explorer, expand the node for the instance containing the DAC to be deleted.

  2. 展開 [管理] 節點。Expand the Management node.

  3. 展開 資料層應用程式 節點。Expand the Data-tier Applications node.

  4. 以滑鼠右鍵按一下要刪除的 DAC,然後選取 [刪除資料層應用程式…] Right-click the DAC to be deleted, and then select Delete Data-tier Application...

  5. 完成精靈對話方塊:Complete the wizard dialogs:

    1. 簡介Introduction

    2. 選擇方法Choose Method

    3. 摘要Summary

    4. 刪除資料層應用程式Delete Data-tier Application

簡介頁面Introduction Page

此頁面描述刪除資料層應用程式的步驟。This page describes the steps for deleting a data-tier application.

不要再顯示此頁面。Do not show this page again. - 按一下此核取方塊,之後就不會再顯示此頁面。- Click the check box to stop the page from being displayed in the future.

下一步 > - 繼續進行 [選擇方法] 頁面。Next > - Proceeds to the Choose Method page.

取消 - 結束精靈,不刪除資料層應用程式或資料庫。Cancel - Ends the wizard without deleting a data-tier application or database.

使用刪除資料層應用程式精靈Using the Delete Data-tier Application Wizard

選擇方法頁面Choose Method Page

使用此頁面來指定用於處理與要刪除的 DAC 相關聯之資料庫的選項。Use this page to specify the option for handling the database associated with the DAC to be deleted.

刪除註冊 - 移除定義資料層應用程式的中繼資料,但讓相關聯的資料庫保持不變。Delete registration - Removes the metadata defining the data-tier application, but leaves the associated database intact.

卸離資料庫 - 移除定義資料層應用程式的中繼資料,並卸離相關聯的資料庫。Detach database - Removes the metadata defining the data-tier application and detaches the associated database.

Database EngineDatabase Engine執行個體無法再參考資料庫,但資料和記錄檔保持不變。The database can no longer be referenced by that instance of the Database EngineDatabase Engine, but the data and log files remain intact.

刪除資料庫 - 移除定義 DAC 的中繼資料,並卸除相關聯的資料庫。Delete database - Removes the metadata defining the DAC and drops the associated database.

資料庫的資料和記錄檔會遭到永久刪除。The data and log files for the database are permanently deleted.

< 上一步 - 回到 [簡介] 頁面。< Previous - Returns to the Introduction page.

下一步 > - 繼續進行 [摘要] 頁面。Next > - Proceeds to the Summary page.

取消 - 結束精靈,不刪除 DAC 或資料庫。Cancel - Ends the wizard without deleting the DAC or database.

使用刪除資料層應用程式精靈Using the Delete Data-tier Application Wizard

摘要頁面Summary Page

使用此頁面來檢閱刪除 DAC 執行個體時,精靈將會採取的動作。Use this page to review the actions the wizard will take when deleting the DAC instance.

檢閱選項摘要 - 檢閱顯示在方塊中的 DAC、資料庫與刪除方法。Review your selection summary - Review the DAC, database, and deletion method displayed in the box. 如果資訊正確,選取 [下一步][完成] 來刪除 DAC。If the information is correct, select either Next or Finish to delete the DAC. 如果 DAC 和資料庫資訊不正確,選取 [取消] ,然後選取正確的 DAC。If the DAC and database information is not correct, select Cancel and select the correct DAC. 如果刪除方法不正確,選取 [上一步] ,返回 [選擇方法] 頁面,然後選取其他方法。If the deletion method is not correct, select Previous to return to the Choose Method page and select a different method.

< 上一步 - 回到 [選擇方法] 頁面以選擇其他刪除方法。< Previous - Returns to the Choose Method page to choose a different delete method.

下一步 > - 使用您在上一頁選擇的方法刪除 DAC 執行個體,然後繼續進行 [刪除資料層應用程式] 頁面。Next > - Deletes the DAC instance using the method you chose on the previous page, and proceeds to the Delete Data-tier Application page.

取消 - 結束精靈,不刪除 DAC 執行個體。Cancel - Ends the wizard without deleting the DAC instance.

使用刪除資料層應用程式精靈Using the Delete Data-tier Application Wizard

刪除資料層應用程式頁面Delete Data-tier Application Page

此頁面會報告刪除作業成功或失敗。This page reports the success or failure of the delete operation.

刪除 DAC - 報告為刪除 DAC 執行個體所採取的每個動作成功或失敗。Deleting the DAC - Reports the success or failure of each action taken to delete the DAC instance. 檢閱資訊以判斷每個動作成功或失敗。Review the information to determine the success or failure of each action. 發生錯誤的所有動作在 [結果] 資料行中都會有一個連結。Any action that encountered an error will have a link in the Result column. 選取連結來檢視該動作的錯誤報告。Select the link to view a report of the error for that action.

儲存報表 - 選取此按鈕可以將刪除報告儲存到 HTML 檔案。Save Report - Select this button to save the deletion report to an HTML file. 此檔案會報告每個動作的狀態,包括所有動作所產生的所有錯誤。The file reports the status of each action, including all errors generated by any of the actions. 預設資料夾為 Windows 帳戶之文件資料夾中的 SQL Server Management Studio\DAC Packages 資料夾。The default folder is a SQL Server Management Studio\DAC Packages folder in the Documents folder of your Windows account..

完成 - 結束精靈。Finish - Ends the wizard.

使用刪除資料層應用程式精靈Using the Delete Data-tier Application Wizard

使用 PowerShellUsing PowerShell

  1. 建立 SMO Server 物件,並將它設定為包含要刪除之 DAC 的執行個體。Create a SMO Server object and set it to the instance that contains the DAC to be deleted.

  2. 開啟 ServerConnection 物件,並連接到相同的執行個體。Open a ServerConnection object and connect to the same instance.

  3. 使用 add_DacActionStartedadd_DacActionFinished 訂閱 DAC 升級事件。Use add_DacActionStarted and add_DacActionFinished to subscribe to the DAC upgrade events.

  4. 指定要刪除的 DAC。Specify the DAC to delete.

  5. 請根據適用的刪除選項,使用下列三組程式碼的其中一組:Use one of three examples, depending on which delete option is appropriate:

    • 若要刪除 DAC 註冊但讓資料庫保持不變,請使用 Unmanage 方法。To delete the DAC registration and leave the database intact, use the Unmanage method.
    • 若要刪除 DAC 註冊並卸離資料庫,請使用 Uninstall 方法並指定 DetachDatabaseTo delete the DAC registration and detach the database, use the Uninstall method and specify DetachDatabase.
    • 若要刪除 DAC 註冊並卸除資料庫,請使用 Uninstall 方法並指定 DropDatabaseTo delete the DAC registration and drop the database, use the Uninstall method and specify DropDatabase.

刪除 DAC 並離開資料庫Delete the DAC and leave the database

下列範例使用 Unmanage 方法來刪除 DAC 但讓資料庫保持不變,以刪除名為 <myApplication> 的 DAC。The following example deletes a DAC named <myApplication> using the Unmanage method to delete the DAC but leave the database intact.

## Set a SMO Server object to the default instance on the local computer.  
CD SQLSERVER:\SQL\localhost\DEFAULT  
$server = Get-Item .  
  
## Open a Common.ServerConnection to the same instance.  
$serverConnection = New-Object Microsoft.SqlServer.Management.Common.ServerConnection($server.ConnectionContext.SqlConnectionObject)  
$serverConnection.Connect()  
$dacStore = New-Object Microsoft.SqlServer.Management.Dac.DacStore($serverConnection)  
  
## Subscribe to the DAC delete events.  
$dacStore.add_DacActionStarted({Write-Host `n`nStarting at $(Get-Date) :: $_.Description})  
$dacStore.add_DacActionFinished({Write-Host Completed at $(Get-Date) :: $_.Description})  
  
## Specify the DAC to delete.  
$dacName  = "<myApplication>"  
  
## Only delete the DAC definition from msdb, the associated database remains active.  
$dacStore.Unmanage($dacName)  

刪除 DAC 並中斷資料庫的連結Delete the DAC and detach the database

下列範例使用 Uninstall 方法來刪除 DAC 並卸離資料庫,以刪除名為 <myApplication> 的 DAC。The following example deletes a DAC named <myApplication> using the Uninstall method to delete the DAC and detach the database.

## Set a SMO Server object to the default instance on the local computer.  
CD SQLSERVER:\SQL\localhost\DEFAULT  
$server = Get-Item .  
  
## Open a Common.ServerConnection to the same instance.  
$serverConnection = New-Object Microsoft.SqlServer.Management.Common.ServerConnection($server.ConnectionContext.SqlConnectionObject)  
$serverConnection.Connect()  
$dacStore = New-Object Microsoft.SqlServer.Management.Dac.DacStore($serverConnection)  
  
## Subscribe to the DAC delete events.  
$dacStore.add_DacActionStarted({Write-Host `n`nStarting at $(Get-Date) :: $_.Description})  
$dacStore.add_DacActionFinished({Write-Host Completed at $(Get-Date) :: $_.Description})  
  
## Specify the DAC to delete.  
$dacName  = "<myApplication>"  
  
## Delete the DAC definition from msdb and detach the associated database.  
$dacStore.Uninstall($dacName, [Microsoft.SqlServer.Management.Dac.DacUninstallMode]::DetachDatabase)  

刪除 DAC 並卸除資料庫Delete the DAC and drop the database

下列範例使用 Uninstall 方法來刪除 DAC 並卸除資料庫,以刪除名為 <myApplication> 的 DAC。The following example deletes a DAC named <myApplication> using the Uninstall method to delete the DAC and drop the database.

## Set a SMO Server object to the default instance on the local computer.  
CD SQLSERVER:\SQL\localhost\DEFAULT  
$server = Get-Item .  
  
## Open a Common.ServerConnection to the same instance.  
$serverConnection = New-Object Microsoft.SqlServer.Management.Common.ServerConnection($server.ConnectionContext.SqlConnectionObject)  
$serverConnection.Connect()  
$dacStore = New-Object Microsoft.SqlServer.Management.Dac.DacStore($serverConnection)  
  
## Subscribe to the DAC delete events.  
$dacStore.add_DacActionStarted({Write-Host `n`nStarting at $(Get-Date) :: $_.Description})  
$dacStore.add_DacActionFinished({Write-Host Completed at $(Get-Date) :: $_.Description})  
  
## Specify the DAC to delete.  
$dacName  = "<myApplication>"  
  
## Delete the DAC definition from msdb and drop the associated database.  
$dacStore.Uninstall($dacName, [Microsoft.SqlServer.Management.Dac.DacUninstallMode]::DropDatabase)  

另請參閱See Also

資料層應用程式 Data-tier Applications
資料層應用程式 Data-tier Applications
部署資料層應用程式 Deploy a Data-tier Application
將資料庫註冊為 DAC Register a Database As a DAC
SQL Server 資料庫的備份與還原 Back Up and Restore of SQL Server Databases
資料庫卸離與附加 (SQL Server)Database Detach and Attach (SQL Server)